mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-08 22:23:11 +00:00
Adds the `metricsdiff` tool. The metricsdiff tool parses two files containing prometheus metrics and calculates the sets of metrics that were added or removed between the two files or have changed labels. This tool is added to ensure that the metrics been generated for `metricsgen` match the bespoke metrics. The following metrics were found to be different between master and the the tool was built with. The output makes sense given that the metrics branch does _not_ contain https://github.com/tendermint/tendermint/pull/8480. ``` ./metricsdiff metrics_master metrics_generated Removes: --- tendermint_consensus_proposal_create_count --- tendermint_consensus_vote_extension_receive_count --- tendermint_consensus_round_voting_power_percent --- tendermint_consensus_proposal_receive_count ```
63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
package main_test
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
metricsdiff "github.com/tendermint/tendermint/scripts/metricsgen/metricsdiff"
|
|
)
|
|
|
|
func TestDiff(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name string
|
|
aContents string
|
|
bContents string
|
|
|
|
want string
|
|
}{
|
|
{
|
|
name: "labels",
|
|
aContents: `
|
|
metric_one{label_one="content", label_two="content"} 0
|
|
`,
|
|
bContents: `
|
|
metric_one{label_three="content", label_four="content"} 0
|
|
`,
|
|
want: `Label changes:
|
|
Metric: metric_one
|
|
+++ label_three
|
|
+++ label_four
|
|
--- label_one
|
|
--- label_two
|
|
`,
|
|
},
|
|
{
|
|
name: "metrics",
|
|
aContents: `
|
|
metric_one{label_one="content"} 0
|
|
`,
|
|
bContents: `
|
|
metric_two{label_two="content"} 0
|
|
`,
|
|
want: `Metric changes:
|
|
+++ metric_two
|
|
--- metric_one
|
|
`,
|
|
},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
bufA := bytes.NewBuffer([]byte{})
|
|
bufB := bytes.NewBuffer([]byte{})
|
|
_, err := io.WriteString(bufA, tc.aContents)
|
|
require.NoError(t, err)
|
|
_, err = io.WriteString(bufB, tc.bContents)
|
|
require.NoError(t, err)
|
|
md, err := metricsdiff.DiffFromReaders(bufA, bufB)
|
|
require.NoError(t, err)
|
|
require.Equal(t, tc.want, md.String())
|
|
})
|
|
}
|
|
}
|