Skip to content

Commit 0937e18

Browse files
committed
Fix GetServices never returns nil
Some storage backends return nil when no services exist, which caused the getServices API to omit the services field or serialize it as null. This breaks the UI schema expectations, which always require an array. Normalize nil to an empty slice in QueryService.GetServices so that all callers receive a consistent, non-nil response. Fixes #7921. Signed-off-by: Sujal Shah <sujalshah28092004@gmail.com>
1 parent 435a23d commit 0937e18

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

cmd/jaeger/internal/extension/jaegerquery/querysvc/service.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ func (qs QueryService) GetTraces(
119119
}
120120

121121
func (qs QueryService) GetServices(ctx context.Context) ([]string, error) {
122-
return qs.traceReader.GetServices(ctx)
122+
services, err := qs.traceReader.GetServices(ctx)
123+
if services == nil {
124+
services = []string{}
125+
}
126+
return services, err
123127
}
124128

125129
func (qs QueryService) GetOperations(

cmd/jaeger/internal/extension/jaegerquery/querysvc/service_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,3 +749,17 @@ func TestGetCapabilities(t *testing.T) {
749749
})
750750
}
751751
}
752+
func TestQueryServiceGetServicesReturnsEmptySlice(t *testing.T) {
753+
reader := new(tracestoremocks.Reader)
754+
reader.
755+
On("GetServices", mock.Anything).
756+
Return(nil, nil).Once()
757+
758+
qs := NewQueryService(reader, nil, QueryServiceOptions{})
759+
760+
services, err := qs.GetServices(context.Background())
761+
762+
require.NoError(t, err)
763+
require.NotNil(t, services)
764+
require.Equal(t, 0, len(services))
765+
}

0 commit comments

Comments
 (0)