Skip to content

Conversation

@ZeynelKoca
Copy link

@ZeynelKoca ZeynelKoca commented Oct 6, 2025

Description

Adds a way to globally configure the state TTL for dynamo (inspired by #1059).

The defined default TTL will only be used if the state request does not explicitly specify a TTL itself.

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

@JoostPV
Copy link

JoostPV commented Oct 16, 2025

Would be nice when the different statestores (Redis and Dynamo) behave in a similar way.

@MyMirelHub
Copy link
Contributor

There will be a slight delay in reviewing the DynamoDB-related PRs. We need to address the missing/disabled tests first, which are being tracked in issue #4047. Thanks for your patience!

Comment on lines +1353 to +1374
t.Run("Explicit TTL overrides default in request with empty metadata", func(t *testing.T) {
defaultTTL := 1200
s := StateStore{
ttlAttributeName: "expiresAt",
ttlInSeconds: &defaultTTL,
}

req := &state.SetRequest{
Key: "test-key",
Metadata: map[string]string{
"ttlInSeconds": "0",
},
}

ttl, err := s.parseTTL(req)
require.NoError(t, err)
require.NotNil(t, ttl)

// Should use explicit value 0, not default
expectedTime := time.Now().Unix()
assert.InDelta(t, expectedTime, *ttl, 2)
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case demonstrates that the behavior for dynamodb would make the setting of this metadata field to 0 to expire immediately, and the same for a negative value. However, if I look at the SET implementation of the redis implementation a value of 0 for the ttl means the key never expires, as does a negative value. I think we should have the same behavior on dynamodb that we have for redis please 🙏 If you can also create a docs PR to add this PR to the docs too that would be greatly appreciated! Feel free to tag me when this is ready for re-review :)

https://github.com/berndverst/components-contrib/blob/master/state/redis/redis.go#L363

Comment on lines +41 to +42
description: |
Allows specifying a default Time-to-live (TTL) in seconds that will be applied to every state store request unless TTL is explicitly defined via the request metadata.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: |
Allows specifying a default Time-to-live (TTL) in seconds that will be applied to every state store request unless TTL is explicitly defined via the request metadata.
description: |
Allows specifying a Time-to-live (TTL) in seconds that will be applied to every state store request unless TTL is explicitly defined via the request metadata.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants