f37e90be18
* add goroutine text profiles to nomad operator debug * add server-id=all to nomad operator debug * fix bug from changing metrics from string to []byte * Add function to return MetricsSummary struct, metrics gotemplate support * fix bug resolving 'server-id=all' when no servers are available * add url to operator_debug tests * removed test section which is used for future operator_debug.go changes * separate metrics from operator, use only structs from go-metrics * ensure parent directories are created as needed * add suggested comments for text debug pprof * move check down to where it is used * add WaitForFiles helper function to wait for multiple files to exist * compact metrics check Co-authored-by: Drew Bailey <2614075+drewbailey@users.noreply.github.com> * fix github's silly apply suggestion Co-authored-by: Drew Bailey <2614075+drewbailey@users.noreply.github.com>
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package api
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestOperator_MetricsSummary(t *testing.T) {
|
|
t.Parallel()
|
|
c, s := makeClient(t, nil, nil)
|
|
defer s.Stop()
|
|
|
|
operator := c.Operator()
|
|
qo := &QueryOptions{
|
|
Params: map[string]string{
|
|
"pretty": "1",
|
|
},
|
|
}
|
|
|
|
metrics, qm, err := operator.MetricsSummary(qo)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, metrics)
|
|
require.NotNil(t, qm)
|
|
require.NotNil(t, metrics.Timestamp) // should always get a TimeStamp
|
|
require.GreaterOrEqual(t, len(metrics.Points), 0) // may not have points yet
|
|
require.GreaterOrEqual(t, len(metrics.Gauges), 1) // should have at least 1 gauge
|
|
require.GreaterOrEqual(t, len(metrics.Counters), 1) // should have at least 1 counter
|
|
require.GreaterOrEqual(t, len(metrics.Samples), 1) // should have at least 1 sample
|
|
}
|
|
|
|
func TestOperator_Metrics_Prometheus(t *testing.T) {
|
|
t.Parallel()
|
|
c, s := makeClient(t, nil, nil)
|
|
defer s.Stop()
|
|
|
|
operator := c.Operator()
|
|
qo := &QueryOptions{
|
|
Params: map[string]string{
|
|
"format": "prometheus",
|
|
},
|
|
}
|
|
|
|
metrics, err := operator.Metrics(qo)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, metrics)
|
|
metricString := string(metrics[:])
|
|
require.Containsf(t, metricString, "# HELP", "expected Prometheus format containing \"# HELP\", got: \n%s", metricString)
|
|
}
|