Skip to content

Commit

Permalink
Add cluster version fix etcd-io#11233, etcd-io#11254, etcd-io#11265
Browse files Browse the repository at this point in the history
  • Loading branch information
wenjiaswe committed Oct 17, 2019
1 parent a038dc6 commit fc5f941
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 1 addition & 5 deletions e2e/etcd_release_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ func TestReleaseUpgrade(t *testing.T) {
}

// expect upgraded cluster version
ver := version.Version
if strings.HasSuffix(ver, "+git") {
ver = strings.Replace(ver, "+git", "", 1)
}
if err := cURLGet(cx.epc, cURLReq{endpoint: "/metrics", expected: fmt.Sprintf(`etcd_cluster_version{cluster_version="%s"} 1`, ver), metricsURLScheme: cx.cfg.metricsURLScheme}); err != nil {
if err := cURLGet(cx.epc, cURLReq{endpoint: "/metrics", expected: fmt.Sprintf(`etcd_cluster_version{cluster_version="%s"} 1`, version.Cluster(version.Version)), metricsURLScheme: cx.cfg.metricsURLScheme}); err != nil {
cx.t.Fatalf("failed get with curl (%v)", err)
}
}
Expand Down
8 changes: 6 additions & 2 deletions etcdserver/membership/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ func (c *RaftCluster) SetVersion(ver *semver.Version, onSet func(*semver.Version
} else {
plog.Noticef("set the initial cluster version to %v", version.Cluster(ver.String()))
}
oldVer := c.version
c.version = ver
mustDetectDowngrade(c.version)
if c.store != nil {
Expand All @@ -377,8 +378,11 @@ func (c *RaftCluster) SetVersion(ver *semver.Version, onSet func(*semver.Version
if c.be != nil {
mustSaveClusterVersionToBackend(c.be, ver)
}
ClusterVersionMetrics.With(prometheus.Labels{"cluster_version": ver.String()}).Set(1)
onSet(ver)
if oldVer != nil {
ClusterVersionMetrics.With(prometheus.Labels{"cluster_version": version.Cluster(oldVer.String())}).Set(0)
}
ClusterVersionMetrics.With(prometheus.Labels{"cluster_version": version.Cluster(ver.String())}).Set(1)
onSet(ver)
}

func (c *RaftCluster) IsReadyToAddNewMember() bool {
Expand Down
2 changes: 1 addition & 1 deletion etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ func (s *EtcdServer) start() {
s.readNotifier = newNotifier()
if s.ClusterVersion() != nil {
plog.Infof("starting server... [version: %v, cluster version: %v]", version.Version, version.Cluster(s.ClusterVersion().String()))
membership.ClusterVersionMetrics.With(prometheus.Labels{"cluster_version": s.ClusterVersion().String()}).Set(1)
membership.ClusterVersionMetrics.With(prometheus.Labels{"cluster_version": version.Cluster(s.ClusterVersion().String())}).Set(1)
} else {
plog.Infof("starting server... [version: %v, cluster version: to_be_decided]", version.Version)
}
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"strings"
"testing"

"go.etcd.io/etcd/version"
"github.com/coreos/etcd/version"
)

func TestV3MetricsSecure(t *testing.T) {
Expand Down Expand Up @@ -50,7 +50,7 @@ func metricsTest(cx ctlCtx) {
if strings.HasSuffix(ver, "+git") {
ver = strings.Replace(ver, "+git", "", 1)
}
if err := cURLGet(cx.epc, cURLReq{endpoint: "/metrics", expected: fmt.Sprintf(`etcd_cluster_version{cluster_version="%s"} 1`, ver), metricsURLScheme: cx.cfg.metricsURLScheme}); err != nil {
if err := cURLGet(cx.epc, cURLReq{endpoint: "/metrics", expected: fmt.Sprintf(`etcd_cluster_version{cluster_version="%s"} 1`, version.Cluster(version.Version)), metricsURLScheme: cx.cfg.metricsURLScheme}); err != nil {
cx.t.Fatalf("failed get with curl (%v)", err)
}
if err := cURLGet(cx.epc, cURLReq{endpoint: "/health", expected: `{"health":"true"}`, metricsURLScheme: cx.cfg.metricsURLScheme}); err != nil {
Expand Down

0 comments on commit fc5f941

Please sign in to comment.