mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 12:44:10 -06:00
3df625e9f4
* Remove specific stats from usage stats service * Create statscollector service * refactor * Update and move tests Mostly equivalent tests to before, but they've been divided over the two services and removed the behavior driven legacy from GoConvey to reduce the complexity of the tests. * Collect featuremgmr metrics (copied over from #47407) I removed the metrics registration from the feature manager in the merge and re-add them in this commit. Separated to make things easier to review.
38 lines
834 B
Go
38 lines
834 B
Go
package usagestats
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type UsageStatsMock struct {
|
|
T testing.TB
|
|
metricsFuncs []MetricsFunc
|
|
}
|
|
|
|
func (usm *UsageStatsMock) RegisterMetricsFunc(fn MetricsFunc) {
|
|
usm.metricsFuncs = append(usm.metricsFuncs, fn)
|
|
}
|
|
|
|
func (usm *UsageStatsMock) GetUsageReport(ctx context.Context) (Report, error) {
|
|
all := make(map[string]interface{})
|
|
for _, fn := range usm.metricsFuncs {
|
|
fnMetrics, err := fn(ctx)
|
|
require.NoError(usm.T, err)
|
|
|
|
for name, value := range fnMetrics {
|
|
all[name] = value
|
|
}
|
|
}
|
|
return Report{Metrics: all}, nil
|
|
}
|
|
|
|
func (usm *UsageStatsMock) ShouldBeReported(_ context.Context, s string) bool {
|
|
return !strings.HasPrefix(s, "unknown")
|
|
}
|
|
|
|
func (usm *UsageStatsMock) RegisterSendReportCallback(_ SendReportCallbackFunc) {}
|