Skip to content

Commit

Permalink
[Backport 7.63.x] discovery: module: sort container tags before parsi…
Browse files Browse the repository at this point in the history
…ng them (#33727)

Co-authored-by: Guillaume Pagnoux <[email protected]>
  • Loading branch information
agent-platform-auto-pr[bot] and Yumasi authored Feb 5, 2025
1 parent 8eba1ad commit e8b0a94
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,9 @@ func getServiceNameFromContainerTags(tags []string) (string, string) {
{"kube_service", nil},
}

// Sort the tags to make the function deterministic
slices.Sort(tags)

for _, tag := range tags {
// Get index of separator between name and value
sepIndex := strings.IndexRune(tag, ':')
Expand All @@ -630,6 +633,11 @@ func getServiceNameFromContainerTags(tags []string) (string, string) {
}

for i := range tagsPriority {
if tagsPriority[i].tagValue != nil {
// We have seen this tag before, we don't need another value.
continue
}

if tag[:sepIndex] != tagsPriority[i].tagName {
// Not a tag we care about; we skip it
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,16 @@ func TestTagsPriority(t *testing.T) {
"service",
"my_service",
},
{
"multiple tags",
[]string{
"service:foo",
"service:bar",
"other:tag",
},
"service",
"bar",
},
}

for _, c := range cases {
Expand Down

0 comments on commit e8b0a94

Please sign in to comment.