Skip to content

Commit

Permalink
[bugfix] Add IP to endpoint key. (cloudprober#535)
Browse files Browse the repository at this point in the history
HTTP probes use endpoint key as identifier to decide when to recreate
probes. During VM recreations, it is possible for VM name to stay the
same but VM IP changes. By adding IP to key, we ensure that in such
cases, HTTP probes are recreated.
  • Loading branch information
ls692 committed Sep 20, 2023
1 parent 31a155f commit 202b0bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
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{
Expand Down

0 comments on commit 202b0bb

Please sign in to comment.