go.etcd.io/etcd@v3.3.27+incompatible/tests/e2e/metrics_test.go (about)

     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  
    15  package e2e
    16  
    17  import (
    18  	"fmt"
    19  	"strings"
    20  	"testing"
    21  
    22  	"github.com/coreos/etcd/version"
    23  )
    24  
    25  func TestV3MetricsSecure(t *testing.T) {
    26  	cfg := configTLS
    27  	cfg.clusterSize = 1
    28  	cfg.metricsURLScheme = "https"
    29  	testCtl(t, metricsTest)
    30  }
    31  
    32  func TestV3MetricsInsecure(t *testing.T) {
    33  	cfg := configTLS
    34  	cfg.clusterSize = 1
    35  	cfg.metricsURLScheme = "http"
    36  	testCtl(t, metricsTest)
    37  }
    38  
    39  func metricsTest(cx ctlCtx) {
    40  	if err := ctlV3Put(cx, "k", "v", ""); err != nil {
    41  		cx.t.Fatal(err)
    42  	}
    43  	if err := cURLGet(cx.epc, cURLReq{endpoint: "/metrics", expected: `etcd_debugging_mvcc_keys_total 1`, metricsURLScheme: cx.cfg.metricsURLScheme}); err != nil {
    44  		cx.t.Fatalf("failed get with curl (%v)", err)
    45  	}
    46  	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 {
    47  		cx.t.Fatalf("failed get with curl (%v)", err)
    48  	}
    49  	ver := version.Version
    50  	if strings.HasSuffix(ver, "+git") {
    51  		ver = strings.Replace(ver, "+git", "", 1)
    52  	}
    53  	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 {
    54  		cx.t.Fatalf("failed get with curl (%v)", err)
    55  	}
    56  	if err := cURLGet(cx.epc, cURLReq{endpoint: "/health", expected: `{"health":"true"}`, metricsURLScheme: cx.cfg.metricsURLScheme}); err != nil {
    57  		cx.t.Fatalf("failed get with curl (%v)", err)
    58  	}
    59  }