metrics_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2017 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package e2e
  15. import (
  16. "fmt"
  17. "strings"
  18. "testing"
  19. "go.etcd.io/etcd/version"
  20. )
  21. func TestV3MetricsSecure(t *testing.T) {
  22. cfg := configTLS
  23. cfg.clusterSize = 1
  24. cfg.metricsURLScheme = "https"
  25. testCtl(t, metricsTest)
  26. }
  27. func TestV3MetricsInsecure(t *testing.T) {
  28. cfg := configTLS
  29. cfg.clusterSize = 1
  30. cfg.metricsURLScheme = "http"
  31. testCtl(t, metricsTest)
  32. }
  33. func metricsTest(cx ctlCtx) {
  34. if err := ctlV3Put(cx, "k", "v", ""); err != nil {
  35. cx.t.Fatal(err)
  36. }
  37. ver := version.Version
  38. if strings.HasSuffix(ver, "-pre") {
  39. ver = strings.Replace(ver, "-pre", "", 1)
  40. }
  41. i := 0
  42. for _, test := range []struct {
  43. endpoint, expected string
  44. }{
  45. {"/metrics", fmt.Sprintf("etcd_mvcc_put_total 2")},
  46. {"/metrics", fmt.Sprintf("etcd_debugging_mvcc_keys_total 1")},
  47. {"/metrics", fmt.Sprintf("etcd_mvcc_delete_total 3")},
  48. {"/metrics", fmt.Sprintf(`etcd_server_version{server_version="%s"} 1`, version.Version)},
  49. {"/metrics", fmt.Sprintf(`etcd_cluster_version{cluster_version="%s"} 1`, ver)},
  50. {"/health", `{"health":"true"}`},
  51. } {
  52. i++
  53. if err := ctlV3Put(cx, fmt.Sprintf("%d", i), "v", ""); err != nil {
  54. cx.t.Fatal(err)
  55. }
  56. if err := ctlV3Del(cx, []string{fmt.Sprintf("%d", i)}, 1); err != nil {
  57. cx.t.Fatal(err)
  58. }
  59. if err := cURLGet(cx.epc, cURLReq{endpoint: test.endpoint, expected: test.expected, metricsURLScheme: cx.cfg.metricsURLScheme}); err != nil {
  60. cx.t.Fatalf("failed get with curl (%v)", err)
  61. }
  62. }
  63. }