metrics_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. if err := cURLGet(cx.epc, cURLReq{endpoint: "/metrics", expected: `etcd_debugging_mvcc_keys_total 1`, metricsURLScheme: cx.cfg.metricsURLScheme}); err != nil {
  38. cx.t.Fatalf("failed get with curl (%v)", err)
  39. }
  40. 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 {
  41. cx.t.Fatalf("failed get with curl (%v)", err)
  42. }
  43. ver := version.Version
  44. if strings.HasSuffix(ver, "+git") {
  45. ver = strings.Replace(ver, "+git", "", 1)
  46. }
  47. 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 {
  48. cx.t.Fatalf("failed get with curl (%v)", err)
  49. }
  50. if err := cURLGet(cx.epc, cURLReq{endpoint: "/health", expected: `{"health":"true"}`, metricsURLScheme: cx.cfg.metricsURLScheme}); err != nil {
  51. cx.t.Fatalf("failed get with curl (%v)", err)
  52. }
  53. }