Files
grafana/pkg/server/instrumentation_service_test.go
Will Assis 4adebd6058 unified-storage: setup ring to shard requests (#103783)
* Updates the instrumentation_server service to use mux instead of the builtin router, and have it store the router in the module server: this is so we can register the /ring endpoint to check the status of the ring
* Create a new Ring service that depends on the instrumentation server and declares it as a dependency for the storage server
* Create standalone MemberlistKV service for Ring service to use
* Update the storage server Search and GetStats handler to distribute requests if applicable
2025-04-25 13:08:44 -04:00

61 lines
1.4 KiB
Go

package server
import (
"context"
"io"
"net/http"
"testing"
"time"
"github.com/grafana/dskit/services"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/setting"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestRunInstrumentationService(t *testing.T) {
cfg := setting.NewCfg()
cfg.HTTPPort = "3001"
ms := ModuleServer{
log: log.New("test-logger"),
cfg: cfg,
promGatherer: prometheus.DefaultGatherer,
}
s, err := ms.initInstrumentationServer()
require.NoError(t, err)
ctx, cancel := context.WithTimeout(context.Background(), 300*time.Second)
defer cancel()
err = services.StartAndAwaitRunning(ctx, s)
require.NoError(t, err)
testCounter := prometheus.NewCounter(prometheus.CounterOpts{
Name: "test_counter",
})
err = prometheus.Register(testCounter)
require.NoError(t, err)
testCounter.Inc()
time.Sleep(100 * time.Millisecond)
client := http.Client{}
res, err := client.Get("http://localhost:3001/metrics")
require.NoError(t, err)
assert.Equal(t, 200, res.StatusCode)
b, err := io.ReadAll(res.Body)
require.NoError(t, err)
resp := string(b[len(b)-16:])
assert.Equal(t, "\ntest_counter 1\n", resp)
err = res.Body.Close()
require.NoError(t, err)
err = services.StopAndAwaitTerminated(ctx, s)
require.NoError(t, err)
}