From b9e3b1025c9dcc57868d0cb2341552790889f419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caner=20=C3=87=C4=B1dam?= Date: Fri, 16 Jun 2023 18:32:22 +0300 Subject: [PATCH 1/3] force bot replacement when shard id changes --- config/agents.go | 10 +++++++--- config/agents_test.go | 13 +++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) 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..300429f0 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: 3, + }, + } + assert.Equal(t, "forta-agent-0x04f65c-de86-3", cfg.ContainerName()) +} + func TestAgentConfig_Equal(t *testing.T) { tests := []struct { name string From 7eaacb1427c3d4009827bcf855bc7067a2ac409c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caner=20=C3=87=C4=B1dam?= Date: Fri, 16 Jun 2023 18:33:01 +0300 Subject: [PATCH 2/3] force replacement --- services/components/containers/definitions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. From 6fe8eb95ee90458af9fd295db28f9014b5a1d3c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caner=20=C3=87=C4=B1dam?= Date: Fri, 16 Jun 2023 18:34:20 +0300 Subject: [PATCH 3/3] use different number --- config/agents_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/agents_test.go b/config/agents_test.go index 300429f0..4e9d2359 100644 --- a/config/agents_test.go +++ b/config/agents_test.go @@ -21,7 +21,7 @@ func TestAgentConfig_ContainerNameSharded(t *testing.T) { ShardConfig: &ShardConfig{ Shards: 5, ShardID: 3, - Target: 3, + Target: 4, }, } assert.Equal(t, "forta-agent-0x04f65c-de86-3", cfg.ContainerName())