Skip to content

Commit

Permalink
Merge pull request #771 from forta-network/caner/forta-1037-replace-b…
Browse files Browse the repository at this point in the history
…ots-when-shard-id-changes

Force bot replacement when shard ID changes
  • Loading branch information
canercidam authored Jun 16, 2023
2 parents 2e9e059 + 6fe8eb9 commit 167a8b3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
10 changes: 7 additions & 3 deletions config/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"fmt"
"strconv"
"strings"

"github.com/forta-network/forta-core-go/protocol"
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions config/agents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion services/components/containers/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 167a8b3

Please sign in to comment.