(t *testing.T)
| 3037 | } |
| 3038 | |
| 3039 | func Test_Ingester_LabelNames(t *testing.T) { |
| 3040 | series := []struct { |
| 3041 | lbls labels.Labels |
| 3042 | value float64 |
| 3043 | timestamp int64 |
| 3044 | }{ |
| 3045 | {labels.FromStrings("__name__", "test_1", "route", "get_user", "status", "200"), 1, 100000}, |
| 3046 | {labels.FromStrings("__name__", "test_1", "route", "get_user", "status", "500"), 1, 110000}, |
| 3047 | {labels.FromStrings("__name__", "test_2"), 2, 200000}, |
| 3048 | } |
| 3049 | |
| 3050 | expected := []string{"__name__", "route", "status"} |
| 3051 | |
| 3052 | // Create ingester |
| 3053 | i, err := prepareIngesterWithBlocksStorage(t, defaultIngesterTestConfig(t), prometheus.NewRegistry()) |
| 3054 | require.NoError(t, err) |
| 3055 | require.NoError(t, services.StartAndAwaitRunning(context.Background(), i)) |
| 3056 | defer services.StopAndAwaitTerminated(context.Background(), i) //nolint:errcheck |
| 3057 | |
| 3058 | // Wait until it's ACTIVE |
| 3059 | test.Poll(t, 1*time.Second, ring.ACTIVE, func() any { |
| 3060 | return i.lifecycler.GetState() |
| 3061 | }) |
| 3062 | |
| 3063 | // Push series |
| 3064 | ctx := user.InjectOrgID(context.Background(), "test") |
| 3065 | |
| 3066 | for _, series := range series { |
| 3067 | req, _ := mockWriteRequest(t, series.lbls, series.value, series.timestamp) |
| 3068 | _, err := i.Push(ctx, req) |
| 3069 | require.NoError(t, err) |
| 3070 | } |
| 3071 | |
| 3072 | tests := map[string]struct { |
| 3073 | limit int |
| 3074 | expected []string |
| 3075 | }{ |
| 3076 | "should return all label names if no limit is set": { |
| 3077 | expected: expected, |
| 3078 | }, |
| 3079 | "should return limited label names if a limit is set": { |
| 3080 | limit: 2, |
| 3081 | expected: expected[:2], |
| 3082 | }, |
| 3083 | } |
| 3084 | |
| 3085 | for testName, testData := range tests { |
| 3086 | t.Run(testName, func(t *testing.T) { |
| 3087 | // Get label names |
| 3088 | res, err := i.LabelNames(ctx, &client.LabelNamesRequest{Limit: int64(testData.limit)}) |
| 3089 | require.NoError(t, err) |
| 3090 | assert.ElementsMatch(t, testData.expected, res.LabelNames) |
| 3091 | }) |
| 3092 | } |
| 3093 | } |
| 3094 | |
| 3095 | func Test_Ingester_LabelValues(t *testing.T) { |
| 3096 | series := []struct { |
nothing calls this directly
no test coverage detected