Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] Add IP to endpoint key. (#535) #538

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion targets/endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ func (ep *Endpoint) Key() string {
}
sort.Strings(labelSlice)

return strings.Join(append([]string{ep.Name, strconv.Itoa(ep.Port)}, labelSlice...), "_")
ip := ""
if ep.IP != nil {
ip = ep.IP.String()
}
return strings.Join(append([]string{ep.Name, ip, strconv.Itoa(ep.Port)}, labelSlice...), "_")
}

// Lister should implement the ListEndpoints method.
Expand Down
10 changes: 7 additions & 3 deletions targets/endpoint/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package endpoint

import (
"fmt"
"net"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -45,24 +46,27 @@ func TestKey(t *testing.T) {
name string
port int
labels map[string]string
ip net.IP
key string
}{
{
name: "t1",
port: 80,
key: "t1_80",
ip: net.ParseIP("10.0.0.1"),
key: "t1_10.0.0.1_80",
},
{
name: "t1",
port: 80,
ip: net.ParseIP("1234:5678::72"),
labels: map[string]string{"app": "cloudprober", "dc": "xx"},
key: "t1_80_app:cloudprober_dc:xx",
key: "t1_1234:5678::72_80_app:cloudprober_dc:xx",
},
{
name: "t1",
port: 80,
labels: map[string]string{"dc": "xx", "app": "cloudprober"},
key: "t1_80_app:cloudprober_dc:xx",
key: "t1__80_app:cloudprober_dc:xx",
},
} {
ep := Endpoint{
ls692 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down