diff --git a/config/agents.go b/config/agents.go index 0a8b7336..3f4711de 100644 --- a/config/agents.go +++ b/config/agents.go @@ -2,6 +2,7 @@ package config import ( "fmt" + "strconv" "strings" "github.com/forta-network/forta-core-go/protocol" @@ -90,9 +91,12 @@ func (ac AgentConfig) ContainerName() string { return fmt.Sprintf("%s-agent-%s", ContainerNamePrefix, utils.ShortenString(ac.ID, 8)) } _, digest := utils.SplitImageRef(ac.Image) - return fmt.Sprintf( - "%s-agent-%s-%s", ContainerNamePrefix, utils.ShortenString(ac.ID, 8), utils.ShortenString(digest, 4), - ) + + parts := []string{ContainerNamePrefix, "agent", utils.ShortenString(ac.ID, 8), utils.ShortenString(digest, 4)} + if ac.IsSharded() { + parts = append(parts, strconv.Itoa(int(ac.ShardConfig.ShardID))) // append the shard id at the end + } + return strings.Join(parts, "-") } func (ac AgentConfig) GrpcPort() string { diff --git a/config/agents_test.go b/config/agents_test.go index f5193f2a..4e9d2359 100644 --- a/config/agents_test.go +++ b/config/agents_test.go @@ -14,6 +14,19 @@ func TestAgentConfig_ContainerName(t *testing.T) { assert.Equal(t, "forta-agent-0x04f65c-de86", cfg.ContainerName()) } +func TestAgentConfig_ContainerNameSharded(t *testing.T) { + cfg := AgentConfig{ + ID: "0x04f65c638f234548104790d7c692c9273d41f82d784b174ff2fdc3e8e5bf1636", + Image: "bafybeibvkqkf7i3c5ouehviwjb2dzbukgqied3cg36axl7gzm23r6ielnu@sha256:de866feeb97cba4cad6343c4137cb48bc798be0136015bec16d97c8ef28852b9", + ShardConfig: &ShardConfig{ + Shards: 5, + ShardID: 3, + Target: 4, + }, + } + assert.Equal(t, "forta-agent-0x04f65c-de86-3", cfg.ContainerName()) +} + func TestAgentConfig_Equal(t *testing.T) { tests := []struct { name string diff --git a/services/components/containers/definitions.go b/services/components/containers/definitions.go index 38cdb598..b010191f 100644 --- a/services/components/containers/definitions.go +++ b/services/components/containers/definitions.go @@ -15,7 +15,7 @@ const ( LabelValueFortaIsBot = "true" // LabelValueStrategyVersion is for versioning the critical changes in container management strategy. // It's effective in deciding if a bot container should be re-created or not. - LabelValueStrategyVersion = "2023-06-07T14:00:00Z" + LabelValueStrategyVersion = "2023-06-16T15:00:00Z" ) // Limits define container limits.