2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2020-10-14 19:16:10 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-03-09 14:28:58 +00:00
|
|
|
"github.com/hashicorp/nomad/api/internal/testutil"
|
2023-01-01 18:57:26 +00:00
|
|
|
"github.com/shoenig/test/must"
|
2020-10-14 19:16:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestOperator_MetricsSummary(t *testing.T) {
|
2022-03-17 13:34:57 +00:00
|
|
|
testutil.Parallel(t)
|
2023-01-01 18:57:26 +00:00
|
|
|
|
2022-12-22 14:21:00 +00:00
|
|
|
c, s := makeClient(t, nil, func(c *testutil.TestServerConfig) {
|
|
|
|
c.DevMode = true
|
|
|
|
})
|
2020-10-14 19:16:10 +00:00
|
|
|
defer s.Stop()
|
|
|
|
|
|
|
|
operator := c.Operator()
|
|
|
|
qo := &QueryOptions{
|
|
|
|
Params: map[string]string{
|
|
|
|
"pretty": "1",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
metrics, qm, err := operator.MetricsSummary(qo)
|
2023-01-01 18:57:26 +00:00
|
|
|
must.NoError(t, err)
|
|
|
|
must.NotNil(t, metrics)
|
|
|
|
must.NotNil(t, qm)
|
|
|
|
must.NotNil(t, metrics.Timestamp) // should always get a TimeStamp
|
|
|
|
must.SliceEmpty(t, metrics.Points) // may not have points yet
|
|
|
|
must.SliceNotEmpty(t, metrics.Gauges) // should have at least 1 gauge
|
|
|
|
must.SliceNotEmpty(t, metrics.Counters) // should have at least 1 counter
|
|
|
|
must.SliceNotEmpty(t, metrics.Samples) // should have at least 1 sample
|
2020-10-14 19:16:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestOperator_Metrics_Prometheus(t *testing.T) {
|
2022-03-17 13:34:57 +00:00
|
|
|
testutil.Parallel(t)
|
2023-01-01 18:57:26 +00:00
|
|
|
|
2021-03-09 14:28:58 +00:00
|
|
|
c, s := makeClient(t, nil, func(c *testutil.TestServerConfig) {
|
2022-12-22 14:21:00 +00:00
|
|
|
c.DevMode = true
|
2021-03-09 14:28:58 +00:00
|
|
|
c.Telemetry = &testutil.Telemetry{PrometheusMetrics: true}
|
|
|
|
})
|
2020-10-14 19:16:10 +00:00
|
|
|
defer s.Stop()
|
|
|
|
|
|
|
|
operator := c.Operator()
|
|
|
|
qo := &QueryOptions{
|
|
|
|
Params: map[string]string{
|
|
|
|
"format": "prometheus",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
metrics, err := operator.Metrics(qo)
|
2023-01-01 18:57:26 +00:00
|
|
|
must.NoError(t, err)
|
|
|
|
must.NotNil(t, metrics)
|
2020-10-14 19:16:10 +00:00
|
|
|
metricString := string(metrics[:])
|
2023-01-01 18:57:26 +00:00
|
|
|
must.StrContains(t, metricString, "# HELP")
|
2020-10-14 19:16:10 +00:00
|
|
|
}
|