[metrics][rpc]: add basic prefix filter test for new rpc metric (#12598)

Signed-off-by: FFMMM <FFMMM@users.noreply.github.com>
This commit is contained in:
FFMMM 2022-03-23 13:29:12 -07:00 committed by GitHub
parent 5bc2b42093
commit 8f98bbda75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 1 deletions

View File

@ -66,7 +66,7 @@ func assertMetricNotExists(t *testing.T, respRec *httptest.ResponseRecorder, met
} }
} }
// TestAgent_NewRPCMetrics test for the new RPC metrics presence. These are the labeled metrics coming from // TestAgent_NewRPCMetrics test for the new RPC metrics. These are the labeled metrics coming from
// agent.rpc.middleware.interceptors package. // agent.rpc.middleware.interceptors package.
func TestAgent_NewRPCMetrics(t *testing.T) { func TestAgent_NewRPCMetrics(t *testing.T) {
skipIfShortTesting(t) skipIfShortTesting(t)
@ -94,6 +94,30 @@ func TestAgent_NewRPCMetrics(t *testing.T) {
assertMetricExists(t, respRec, metricsPrefix+"_rpc_server_call") assertMetricExists(t, respRec, metricsPrefix+"_rpc_server_call")
}) })
t.Run("Check that new rpc metrics can be filtered out", func(t *testing.T) {
metricsPrefix := "new_rpc_metrics_2"
hcl := fmt.Sprintf(`
telemetry = {
prometheus_retention_time = "5s"
disable_hostname = true
metrics_prefix = "%s"
prefix_filter = ["-%s.rpc.server.call"]
}
`, metricsPrefix, metricsPrefix)
a := StartTestAgent(t, TestAgent{HCL: hcl})
defer a.Shutdown()
var out struct{}
err := a.RPC("Status.Ping", struct{}{}, &out)
require.NoError(t, err)
respRec := httptest.NewRecorder()
recordPromMetrics(t, a, respRec)
assertMetricNotExists(t, respRec, metricsPrefix+"_rpc_server_call")
})
} }
// TestHTTPHandlers_AgentMetrics_ConsulAutopilot_Prometheus adds testing around // TestHTTPHandlers_AgentMetrics_ConsulAutopilot_Prometheus adds testing around