metrics_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. cx.t.Skip()
  35. if err := ctlV3Put(cx, "k", "v", ""); err != nil {
  36. cx.t.Fatal(err)
  37. }
  38. ver := version.Version
  39. if strings.HasSuffix(ver, "-pre") {
  40. ver = strings.Replace(ver, "-pre", "", 1)
  41. }
  42. i := 0
  43. for _, test := range []struct {
  44. endpoint, expected string
  45. }{
  46. {"/metrics", fmt.Sprintf("etcd_mvcc_put_total 2")},
  47. {"/metrics", fmt.Sprintf("etcd_debugging_mvcc_keys_total 1")},
  48. {"/metrics", fmt.Sprintf("etcd_mvcc_delete_total 3")},
  49. {"/metrics", fmt.Sprintf(`etcd_server_version{server_version="%s"} 1`, version.Version)},
  50. {"/metrics", fmt.Sprintf(`etcd_cluster_version{cluster_version="%s"} 1`, ver)},
  51. {"/health", `{"health":"true"}`},
  52. } {
  53. i++
  54. if err := ctlV3Put(cx, fmt.Sprintf("%d", i), "v", ""); err != nil {
  55. cx.t.Fatal(err)
  56. }
  57. if err := ctlV3Del(cx, []string{fmt.Sprintf("%d", i)}, 1); err != nil {
  58. cx.t.Fatal(err)
  59. }
  60. if err := cURLGet(cx.epc, cURLReq{endpoint: test.endpoint, expected: test.expected, metricsURLScheme: cx.cfg.metricsURLScheme}); err != nil {
  61. cx.t.Fatalf("failed get with curl (%v)", err)
  62. }
  63. }
  64. }