Skip to content

Commit

Permalink
refactor(transform): Use Object Src Key in KV Store Lock (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
jshlbrd committed Jun 8, 2024
1 parent d6b6c42 commit 18b2b44
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 3 additions & 3 deletions build/config/substation.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@
settings: std.prune(std.mergePatch(default, $.helpers.abbv(settings))),
},
set(settings={}): {
local default = $.transform.enrich.kv_store.default { ttl_key: null, ttl_offset: "0s" },
local default = $.transform.enrich.kv_store.default { ttl_key: null, ttl_offset: '0s' },

type: 'enrich_kv_store_set',
settings: std.prune(std.mergePatch(default, $.helpers.abbv(settings))),
Expand Down Expand Up @@ -526,11 +526,11 @@
kv_store: {
lock(settings={}): {
local default = {
object: $.config.object { lock_key: null, ttl_key: null },
object: $.config.object { ttl_key: null },
transform: null,
kv_store: null,
prefix: null,
ttl_offset: "0s",
ttl_offset: '0s',
},

type: 'meta_kv_store_lock',
Expand Down
6 changes: 1 addition & 5 deletions transform/meta_kv_store_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import (
)

type metaVStoreLockObjectConfig struct {
// LockKey retrieves a value from an object that is used as the key to lock
// the item in the KV store. If this value is not set, then the SHA256 hash
// of the message is used as the key.
LockKey string `json:"lock_key"`
// TTLKey retrieves a value from an object that is used as the time-to-live (TTL)
// of the item locked in the KV store. This value must be an integer that represents
// the Unix time when the item will be evicted from the store. Any precision greater
Expand Down Expand Up @@ -146,7 +142,7 @@ func (tf *metaKVStoreLock) Transform(ctx context.Context, msg *message.Message)

// By default, the lock key is the SHA256 hash of the message.
var lockKey string
v := msg.GetValue(tf.conf.Object.LockKey)
v := msg.GetValue(tf.conf.Object.SourceKey)
if !v.Exists() {
sum := sha256.Sum256(msg.Data())
lockKey = fmt.Sprintf("%x", sum)
Expand Down

0 comments on commit 18b2b44

Please sign in to comment.