(t *testing.T)
| 3093 | } |
| 3094 | |
| 3095 | func Test_Ingester_LabelValues(t *testing.T) { |
| 3096 | series := []struct { |
| 3097 | lbls labels.Labels |
| 3098 | value float64 |
| 3099 | timestamp int64 |
| 3100 | }{ |
| 3101 | {labels.FromStrings("__name__", "test_1", "route", "get_user", "status", "200"), 1, 100000}, |
| 3102 | {labels.FromStrings("__name__", "test_1", "route", "get_user", "status", "500"), 1, 110000}, |
| 3103 | {labels.FromStrings("__name__", "test_2"), 2, 200000}, |
| 3104 | } |
| 3105 | |
| 3106 | expected := map[string][]string{ |
| 3107 | "__name__": {"test_1", "test_2"}, |
| 3108 | "status": {"200", "500"}, |
| 3109 | "route": {"get_user"}, |
| 3110 | "unknown": {}, |
| 3111 | } |
| 3112 | |
| 3113 | // Create ingester |
| 3114 | i, err := prepareIngesterWithBlocksStorage(t, defaultIngesterTestConfig(t), prometheus.NewRegistry()) |
| 3115 | require.NoError(t, err) |
| 3116 | require.NoError(t, services.StartAndAwaitRunning(context.Background(), i)) |
| 3117 | defer services.StopAndAwaitTerminated(context.Background(), i) //nolint:errcheck |
| 3118 | |
| 3119 | // Wait until it's ACTIVE |
| 3120 | test.Poll(t, 1*time.Second, ring.ACTIVE, func() any { |
| 3121 | return i.lifecycler.GetState() |
| 3122 | }) |
| 3123 | |
| 3124 | // Push series |
| 3125 | ctx := user.InjectOrgID(context.Background(), "test") |
| 3126 | |
| 3127 | for _, series := range series { |
| 3128 | req, _ := mockWriteRequest(t, series.lbls, series.value, series.timestamp) |
| 3129 | _, err := i.Push(ctx, req) |
| 3130 | require.NoError(t, err) |
| 3131 | } |
| 3132 | |
| 3133 | tests := map[string]struct { |
| 3134 | limit int64 |
| 3135 | match []*labels.Matcher |
| 3136 | }{ |
| 3137 | "should return all label values if no limit is set": { |
| 3138 | limit: 0, |
| 3139 | }, |
| 3140 | "should return limited label values if a limit is set": { |
| 3141 | limit: 1, |
| 3142 | }, |
| 3143 | } |
| 3144 | |
| 3145 | for testName, testData := range tests { |
| 3146 | t.Run(testName, func(t *testing.T) { |
| 3147 | for labelName, expectedValues := range expected { |
| 3148 | req := &client.LabelValuesRequest{LabelName: labelName, Limit: testData.limit} |
| 3149 | res, err := i.LabelValues(ctx, req) |
| 3150 | require.NoError(t, err) |
| 3151 | if testData.limit > 0 && len(expectedValues) > int(testData.limit) { |
| 3152 | expectedValues = expectedValues[:testData.limit] |
nothing calls this directly
no test coverage detected