Skip to content

Commit

Permalink
Merge pull request #10962 from hexfusion/promote_mvcc
Browse files Browse the repository at this point in the history
metrics: promote etcd_debugging_mvcc put_total and delete_total
  • Loading branch information
gyuho authored Aug 1, 2019
2 parents 149e5dc + f46ee91 commit 5ef8f27
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG-3.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ Note that any `etcd_debugging_*` metrics are experimental and subject to change.
- Change [gRPC proxy to expose etcd server endpoint /metrics](https://github.com/etcd-io/etcd/pull/10618).
- The metrics that were exposed via the proxy were not etcd server members but instead the proxy itself.
- Fix bug where [db_compaction_total_duration_milliseconds metric incorrectly measured duration as 0](https://github.com/etcd-io/etcd/pull/10646).
- Promote [`etcd_debugging_mvcc_put_total`](https://github.com/etcd-io/etcd/pull/10962) Prometheus metric to etcd_mvcc_put_total.
- Promote [`etcd_debugging_mvcc_delete_total`](https://github.com/etcd-io/etcd/pull/10962) Prometheus metric to etcd_mvcc_delete_total.

### Security, Authentication

Expand Down
18 changes: 18 additions & 0 deletions mvcc/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ var (
})

putCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: "etcd",
Subsystem: "mvcc",
Name: "put_total",
Help: "Total number of puts seen by this member.",
})

// TODO: remove in 3.5 release
putCounterDebug = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: "etcd_debugging",
Subsystem: "mvcc",
Expand All @@ -38,6 +47,15 @@ var (
})

deleteCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: "etcd",
Subsystem: "mvcc",
Name: "delete_total",
Help: "Total number of deletes seen by this member.",
})

// TODO: remove in 3.5 release
deleteCounterDebug = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: "etcd_debugging",
Subsystem: "mvcc",
Expand Down
4 changes: 4 additions & 0 deletions mvcc/metrics_txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,9 @@ func (tw *metricsTxnWrite) End() {
}
rangeCounter.Add(float64(tw.ranges))
putCounter.Add(float64(tw.puts))
// TODO: remove in 3.5 release
putCounterDebug.Add(float64(tw.puts))
deleteCounter.Add(float64(tw.deletes))
// TODO: remove in 3.5 release
deleteCounterDebug.Add(float64(tw.deletes))
}
34 changes: 23 additions & 11 deletions tests/e2e/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,32 @@ func metricsTest(cx ctlCtx) {
if err := ctlV3Put(cx, "k", "v", ""); err != nil {
cx.t.Fatal(err)
}
if err := cURLGet(cx.epc, cURLReq{endpoint: "/metrics", expected: `etcd_debugging_mvcc_keys_total 1`, metricsURLScheme: cx.cfg.metricsURLScheme}); err != nil {
cx.t.Fatalf("failed get with curl (%v)", err)
}
if err := cURLGet(cx.epc, cURLReq{endpoint: "/metrics", expected: fmt.Sprintf(`etcd_server_version{server_version="%s"} 1`, version.Version), metricsURLScheme: cx.cfg.metricsURLScheme}); err != nil {
cx.t.Fatalf("failed get with curl (%v)", err)
}
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 {
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 {
cx.t.Fatalf("failed get with curl (%v)", err)

i := 0
for _, test := range []struct {
endpoint, expected string
}{
{"/metrics", fmt.Sprintf("etcd_mvcc_put_total 2")},
{"/metrics", fmt.Sprintf("etcd_debugging_mvcc_keys_total 1")},
{"/metrics", fmt.Sprintf("etcd_mvcc_delete_total 3")},
{"/metrics", fmt.Sprintf(`etcd_server_version{server_version="%s"} 1`, version.Version)},
{"/metrics", fmt.Sprintf(`etcd_cluster_version{cluster_version="%s"} 1`, ver)},
{"/health", `{"health":"true"}`},
} {
i++
if err := ctlV3Put(cx, fmt.Sprintf("%d", i), "v", ""); err != nil {
cx.t.Fatal(err)
}
if err := ctlV3Del(cx, []string{fmt.Sprintf("%d", i)}, 1); err != nil {
cx.t.Fatal(err)
}

if err := cURLGet(cx.epc, cURLReq{endpoint: test.endpoint, expected: test.expected, metricsURLScheme: cx.cfg.metricsURLScheme}); err != nil {
cx.t.Fatalf("failed get with curl (%v)", err)
}
}
}

0 comments on commit 5ef8f27

Please sign in to comment.