fix(observability-proxy): check the lookup cap before dropping empty names

The store cuts a lookup at the cap plus one value. Dropping empty
values first could bring such a cut list back under the cap and serve
it as complete, hiding the application's other pods without the 422
that asks for a shorter range.

Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
This commit is contained in:
ZverGuy committed 2026-11-10 04:03:24 +07:00
1 parent e6697ea4f1
commit dd7116ea45
2 files changed
+7

No files matched your search

+5
View File
@@ -148,6 +148,11 @@ func (s *Server) lookupNames(ctx context.Context, r *http.Request, store, label,
if body.Status != "success" {
return nil, errorf(http.StatusBadGateway, "metrics store answered status %q", body.Status)
}
if len(body.Data) > limit {
// Over the cap before dropping empty values: the store cut the
// list at limit+1, so a shorter filtered list could hide names.
return body.Data, nil
}
names := body.Data[:0]
for _, n := range body.Data {
if n != "" {
@@ -215,6 +215,8 @@ func TestServerApplicationMetricsBranches(t *testing.T) {
want: []string{wantIdentityBranch, `{namespace="tenant-a",persistentvolumeclaim=~"^(v)$"}`}},
{name: "pods over the cap", pods: []string{"p", "q"}, cfg: Config{Metrics: MetricsConfig{App: AppScopeLimits{Lookback: time.Hour, MaxPods: 1, MaxPVCs: 1}}},
path: "api/v1/query?query=up", wantCode: http.StatusUnprocessableEntity},
{name: "over the cap with an empty name", pods: []string{"", "p"}, cfg: Config{Metrics: MetricsConfig{App: AppScopeLimits{Lookback: time.Hour, MaxPods: 1, MaxPVCs: 1}}},
path: "api/v1/query?query=up", wantCode: http.StatusUnprocessableEntity},
{name: "pvcs over the cap", pods: []string{"p"}, pvcs: []string{"v", "w"}, cfg: Config{Metrics: MetricsConfig{App: AppScopeLimits{Lookback: time.Hour, MaxPods: 1, MaxPVCs: 1}}},
path: "api/v1/query?query=up", wantCode: http.StatusUnprocessableEntity},
{name: "labels get the branches as match[]", pods: []string{"p"}, path: "api/v1/labels", wantCode: http.StatusOK, want: []string{wantIdentityBranch, podBranch}},