-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add etcd_debugging_lease_total gauge metric
- Loading branch information
Showing
3 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// Copyright 2022 The etcd Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package lease | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus/testutil" | ||
"github.com/stretchr/testify/require" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestLeaseGranted(t *testing.T) { | ||
// Test the leaseGranted metric | ||
// This is a counter metric, which means it can only be incremented | ||
// The metric is incremented by 10 and we check if it is 10 | ||
leaseGranted.Add(10) | ||
expected := ` | ||
# HELP etcd_debugging_lease_granted_total The total number of granted leases. | ||
# TYPE etcd_debugging_lease_granted_total counter | ||
etcd_debugging_lease_granted_total 10 | ||
` | ||
err := testutil.CollectAndCompare(leaseGranted, strings.NewReader(expected)) | ||
require.NoError(t, err, "Collected metrics did not match expected metrics: %v", err) | ||
} | ||
|
||
func TestNewLeaseRevoked(t *testing.T) { | ||
// Test the leaseRevoked metric | ||
// This is a counter metric, which means it can only be incremented | ||
// The metric is incremented by 10 and we check if it is 10 | ||
leaseRevoked.Add(10) | ||
expected := ` | ||
# HELP etcd_debugging_lease_revoked_total The total number of revoked leases. | ||
# TYPE etcd_debugging_lease_revoked_total counter | ||
etcd_debugging_lease_revoked_total 10 | ||
` | ||
err := testutil.CollectAndCompare(leaseRevoked, strings.NewReader(expected)) | ||
require.NoError(t, err, "Collected metrics did not match expected metrics: %v", err) | ||
} | ||
|
||
func TestLeaseRenewed(t *testing.T) { | ||
// Test the leaseRenewed metric | ||
// This is a counter metric, which means it can only be incremented | ||
// The metric is incremented by 10 and we check if it is 10 | ||
leaseRenewed.Add(10) | ||
expected := ` | ||
# HELP etcd_debugging_lease_renewed_total The number of renewed leases seen by the leader. | ||
# TYPE etcd_debugging_lease_renewed_total counter | ||
etcd_debugging_lease_renewed_total 10 | ||
` | ||
err := testutil.CollectAndCompare(leaseRenewed, strings.NewReader(expected)) | ||
require.NoError(t, err, "Collected metrics did not match expected metrics: %v", err) | ||
} | ||
|
||
func TestLeaseTotalTTLs(t *testing.T) { | ||
// Test the leaseTotalTTLs metric | ||
// This is a histogram metric, which means it can be incremented and observed | ||
// The metric is incremented by 10 and we check if it is 10 | ||
leaseTotalTTLs.Observe(10) | ||
expected := ` | ||
# HELP etcd_debugging_lease_ttl_total Bucketed histogram of lease TTLs. | ||
# TYPE etcd_debugging_lease_ttl_total histogram | ||
etcd_debugging_lease_ttl_total_bucket{le="1"} 0 | ||
etcd_debugging_lease_ttl_total_bucket{le="2"} 0 | ||
etcd_debugging_lease_ttl_total_bucket{le="4"} 0 | ||
etcd_debugging_lease_ttl_total_bucket{le="8"} 0 | ||
etcd_debugging_lease_ttl_total_bucket{le="16"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="32"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="64"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="128"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="256"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="512"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="1024"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="2048"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="4096"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="8192"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="16384"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="32768"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="65536"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="131072"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="262144"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="524288"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="1.048576e+06"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="2.097152e+06"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="4.194304e+06"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="8.388608e+06"} 1 | ||
etcd_debugging_lease_ttl_total_bucket{le="+Inf"} 1 | ||
etcd_debugging_lease_ttl_total_sum 10 | ||
etcd_debugging_lease_ttl_total_count 1 | ||
` | ||
err := testutil.CollectAndCompare(leaseTotalTTLs, strings.NewReader(expected)) | ||
require.NoError(t, err, "Collected metrics did not match expected metrics: %v", err) | ||
} | ||
|
||
func TestLeaseTotal(t *testing.T) { | ||
// Test the leaseTotal metric | ||
// This is a gauge metric, which means it can be set to any value | ||
// The metric is set to 10 and we check if it is 10 | ||
leaseTotal.Set(10) | ||
expected := ` | ||
# HELP etcd_debugging_lease_total The total number of active leases. | ||
# TYPE etcd_debugging_lease_total gauge | ||
etcd_debugging_lease_total 10 | ||
` | ||
err := testutil.CollectAndCompare(leaseTotal, strings.NewReader(expected)) | ||
require.NoError(t, err, "Collected metrics did not match expected metrics: %v", err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters