diff --git a/packages/grafana-data/src/types/scopes.ts b/packages/grafana-data/src/types/scopes.ts index b90a0e9feb2..e3321e2a8db 100644 --- a/packages/grafana-data/src/types/scopes.ts +++ b/packages/grafana-data/src/types/scopes.ts @@ -49,10 +49,10 @@ export interface ScopeSpecFilter { export interface ScopeSpec { title: string; - type: string; - description: string; - category: string; - filters: ScopeSpecFilter[]; + // Used to display the title next to the selected scope and expand the selector to the proper path. + // This will override whichever is selected from in the selector. + defaultPath?: string[]; + filters?: ScopeSpecFilter[]; } // TODO: Use Resource from apiserver when we export the types diff --git a/packages/grafana-prometheus/src/language_provider.ts b/packages/grafana-prometheus/src/language_provider.ts index 0419295ab16..568acddba64 100644 --- a/packages/grafana-prometheus/src/language_provider.ts +++ b/packages/grafana-prometheus/src/language_provider.ts @@ -488,7 +488,9 @@ export default class PromQlLanguageProvider extends LanguageProvider implements }) ), scopes: scopes?.reduce((acc, scope) => { - acc.push(...scope.spec.filters); + if (scope.spec.filters) { + acc.push(...scope.spec.filters); + } return acc; }, []), diff --git a/pkg/apimachinery/apis/common/v0alpha1/types.go b/pkg/apimachinery/apis/common/v0alpha1/types.go index 34b21adaa3e..94f5670a89a 100644 --- a/pkg/apimachinery/apis/common/v0alpha1/types.go +++ b/pkg/apimachinery/apis/common/v0alpha1/types.go @@ -52,17 +52,22 @@ type Scope struct { } type ScopeSpec struct { - Title string `json:"title"` - Description string `json:"description"` + Title string `json:"title"` + // Provides a default path for the scope. This refers to a list of nodes in the selector. This is used to display the title next to the selected scope and expand the selector to the proper path. + // This will override whichever is selected from in the selector. + // The path is a list of node ids, starting at the direct parent of the selected node towards the root. + // +listType=atomic + DefaultPath []string `json:"defaultPath,omitempty"` // +listType=atomic - Filters []ScopeFilter `json:"filters"` + Filters []ScopeFilter `json:"filters,omitempty"` } type ScopeFilter struct { Key string `json:"key"` Value string `json:"value"` // Values is used for operators that require multiple values (e.g. one-of and not-one-of). + // +listType=atomic Values []string `json:"values,omitempty"` Operator FilterOperator `json:"operator"` } diff --git a/pkg/apimachinery/apis/common/v0alpha1/zz_generated.deepcopy.go b/pkg/apimachinery/apis/common/v0alpha1/zz_generated.deepcopy.go index d3f8e64dbff..41c6e53441b 100644 --- a/pkg/apimachinery/apis/common/v0alpha1/zz_generated.deepcopy.go +++ b/pkg/apimachinery/apis/common/v0alpha1/zz_generated.deepcopy.go @@ -94,6 +94,11 @@ func (in *ScopeFilter) DeepCopy() *ScopeFilter { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ScopeSpec) DeepCopyInto(out *ScopeSpec) { *out = *in + if in.DefaultPath != nil { + in, out := &in.DefaultPath, &out.DefaultPath + *out = make([]string, len(*in)) + copy(*out, *in) + } if in.Filters != nil { in, out := &in.Filters, &out.Filters *out = make([]ScopeFilter, len(*in)) diff --git a/pkg/apimachinery/apis/common/v0alpha1/zz_generated.openapi.go b/pkg/apimachinery/apis/common/v0alpha1/zz_generated.openapi.go index 34424e88e3d..b3042736e0c 100644 --- a/pkg/apimachinery/apis/common/v0alpha1/zz_generated.openapi.go +++ b/pkg/apimachinery/apis/common/v0alpha1/zz_generated.openapi.go @@ -200,6 +200,11 @@ func schema_apimachinery_apis_common_v0alpha1_ScopeFilter(ref common.ReferenceCa }, }, "values": { + VendorExtensible: spec.VendorExtensible{ + Extensions: spec.Extensions{ + "x-kubernetes-list-type": "atomic", + }, + }, SchemaProps: spec.SchemaProps{ Description: "Values is used for operators that require multiple values (e.g. one-of and not-one-of).", Type: []string{"array"}, @@ -243,11 +248,24 @@ func schema_apimachinery_apis_common_v0alpha1_ScopeSpec(ref common.ReferenceCall Format: "", }, }, - "description": { + "defaultPath": { + VendorExtensible: spec.VendorExtensible{ + Extensions: spec.Extensions{ + "x-kubernetes-list-type": "atomic", + }, + }, SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", + Description: "Provides a default path for the scope. This refers to a list of nodes in the selector. This is used to display the title next to the selected scope and expand the selector to the proper path. This will override whichever is selected from in the selector. The path is a list of node ids, starting at the direct parent of the selected node towards the root.", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, }, }, "filters": { @@ -269,7 +287,7 @@ func schema_apimachinery_apis_common_v0alpha1_ScopeSpec(ref common.ReferenceCall }, }, }, - Required: []string{"title", "description", "filters"}, + Required: []string{"title"}, }, }, Dependencies: []string{ diff --git a/pkg/apimachinery/apis/common/v0alpha1/zz_generated.openapi_violation_exceptions.list b/pkg/apimachinery/apis/common/v0alpha1/zz_generated.openapi_violation_exceptions.list index e4491e5ef86..caca0df1147 100644 --- a/pkg/apimachinery/apis/common/v0alpha1/zz_generated.openapi_violation_exceptions.list +++ b/pkg/apimachinery/apis/common/v0alpha1/zz_generated.openapi_violation_exceptions.list @@ -1,4 +1,3 @@ -API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1,ScopeFilter,Values API rule violation: names_match,github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1,Unstructured,Object API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,APIResourceList,APIResources API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,Duration,Duration diff --git a/pkg/promlib/models/query.go b/pkg/promlib/models/query.go index c54e51fea41..ae56d929ec2 100644 --- a/pkg/promlib/models/query.go +++ b/pkg/promlib/models/query.go @@ -80,10 +80,8 @@ type PrometheusQueryProperties struct { type ScopeSpec struct { Name string `json:"name"` // This is the identifier from metadata.name of the scope model. Title string `json:"title"` - Type string `json:"type"` - Description string `json:"description"` - Category string `json:"category"` - Filters []ScopeFilter `json:"filters"` + DefaultPath []string `json:"defaultPath,omitempty"` + Filters []ScopeFilter `json:"filters,omitempty"` } // ScopeFilter is a hand copy of the ScopeFilter struct from pkg/apis/scope/v0alpha1/types.go diff --git a/pkg/promlib/models/query.panel.schema.json b/pkg/promlib/models/query.panel.schema.json index 12f985e9292..c6ca6a172b8 100644 --- a/pkg/promlib/models/query.panel.schema.json +++ b/pkg/promlib/models/query.panel.schema.json @@ -188,18 +188,14 @@ "type": "object", "required": [ "name", - "title", - "type", - "description", - "category", - "filters" + "title" ], "properties": { - "category": { - "type": "string" - }, - "description": { - "type": "string" + "defaultPath": { + "type": "array", + "items": { + "type": "string" + } }, "filters": { "type": "array", @@ -238,9 +234,6 @@ }, "title": { "type": "string" - }, - "type": { - "type": "string" } }, "additionalProperties": false diff --git a/pkg/promlib/models/query.request.schema.json b/pkg/promlib/models/query.request.schema.json index c8279deeb37..0e533b8e5c7 100644 --- a/pkg/promlib/models/query.request.schema.json +++ b/pkg/promlib/models/query.request.schema.json @@ -198,18 +198,14 @@ "type": "object", "required": [ "name", - "title", - "type", - "description", - "category", - "filters" + "title" ], "properties": { - "category": { - "type": "string" - }, - "description": { - "type": "string" + "defaultPath": { + "type": "array", + "items": { + "type": "string" + } }, "filters": { "type": "array", @@ -248,9 +244,6 @@ }, "title": { "type": "string" - }, - "type": { - "type": "string" } }, "additionalProperties": false diff --git a/pkg/promlib/models/query.types.json b/pkg/promlib/models/query.types.json index 052d0998eac..6d29e934973 100644 --- a/pkg/promlib/models/query.types.json +++ b/pkg/promlib/models/query.types.json @@ -8,7 +8,7 @@ { "metadata": { "name": "default", - "resourceVersion": "1725885733879", + "resourceVersion": "1758739325095", "creationTimestamp": "2024-03-25T13:19:04Z" }, "spec": { @@ -105,11 +105,11 @@ "additionalProperties": false, "description": "ScopeSpec is a hand copy of the ScopeSpec struct from pkg/apis/scope/v0alpha1/types.go to avoid import (temp fix).", "properties": { - "category": { - "type": "string" - }, - "description": { - "type": "string" + "defaultPath": { + "items": { + "type": "string" + }, + "type": "array" }, "filters": { "items": { @@ -148,18 +148,11 @@ }, "title": { "type": "string" - }, - "type": { - "type": "string" } }, "required": [ "name", - "title", - "type", - "description", - "category", - "filters" + "title" ], "type": "object" }, diff --git a/public/app/features/scopes/selector/ScopesSelectorService.test.ts b/public/app/features/scopes/selector/ScopesSelectorService.test.ts index d6f8c2f09bf..5721d1daaf8 100644 --- a/public/app/features/scopes/selector/ScopesSelectorService.test.ts +++ b/public/app/features/scopes/selector/ScopesSelectorService.test.ts @@ -17,9 +17,6 @@ describe('ScopesSelectorService', () => { }, spec: { title: 'test-scope', - type: 'scope', - description: 'test scope', - category: 'scope', filters: [], }, }; @@ -30,9 +27,6 @@ describe('ScopesSelectorService', () => { }, spec: { title: 'test-scope', - type: 'scope', - category: 'scope', - description: 'test scope', filters: [], }, }; @@ -402,9 +396,6 @@ describe('ScopesSelectorService', () => { metadata: { name: 'test-scope' }, spec: { title: 'test-scope', - type: 'scope', - category: 'scope', - description: 'test scope', filters: [], }, parentNode: { @@ -433,9 +424,6 @@ describe('ScopesSelectorService', () => { metadata: { name: 'test-scope' }, spec: { title: 'test-scope', - type: 'scope', - category: 'scope', - description: 'test scope', filters: [], }, parentNode: { @@ -455,9 +443,6 @@ describe('ScopesSelectorService', () => { metadata: { name: 'test-scope' }, spec: { title: 'test-scope', - type: 'scope', - category: 'scope', - description: 'test scope', filters: [], }, parentNode: { @@ -485,9 +470,6 @@ describe('ScopesSelectorService', () => { metadata: { name: 'valid-scope' }, spec: { title: 'valid-scope', - type: 'scope', - category: 'scope', - description: 'valid scope', filters: [], }, parentNode: { @@ -506,9 +488,6 @@ describe('ScopesSelectorService', () => { metadata: { name: 'invalid-scope-1' }, spec: { title: 'invalid-scope-1', - type: 'scope', - category: 'scope', - description: 'invalid scope 1', filters: [], }, parentNode: { @@ -523,9 +502,6 @@ describe('ScopesSelectorService', () => { metadata: { name: 'invalid-scope-2' }, spec: { title: 'invalid-scope-2', - type: 'scope', - category: 'scope', - description: 'invalid scope 2', filters: [], }, parentNode: { diff --git a/public/app/features/scopes/selector/types.ts b/public/app/features/scopes/selector/types.ts index c6a2a883c8f..f4eb0a4c876 100644 --- a/public/app/features/scopes/selector/types.ts +++ b/public/app/features/scopes/selector/types.ts @@ -33,10 +33,8 @@ export const ScopeSpecFilterSchema = z.object({ export const ScopeSpecSchema = z.object({ title: z.string(), - type: z.string().optional(), - description: z.string().optional(), - category: z.string().optional(), - filters: z.array(ScopeSpecFilterSchema), + defaultPath: z.array(z.string()).optional(), + filters: z.array(ScopeSpecFilterSchema).optional(), }); export const ScopeSchema = z.object({ diff --git a/public/app/features/scopes/tests/utils/mocks.ts b/public/app/features/scopes/tests/utils/mocks.ts index 2482e9c2053..a94093747c9 100644 --- a/public/app/features/scopes/tests/utils/mocks.ts +++ b/public/app/features/scopes/tests/utils/mocks.ts @@ -7,9 +7,6 @@ export const mocksScopes: Scope[] = [ metadata: { name: 'cloud' }, spec: { title: 'Cloud', - type: 'indexHelper', - description: 'redundant label filter but makes queries faster', - category: 'indexHelpers', filters: [{ key: 'cloud', value: '.*', operator: 'regex-match' }], }, }, @@ -17,9 +14,6 @@ export const mocksScopes: Scope[] = [ metadata: { name: 'dev' }, spec: { title: 'Dev', - type: 'cloud', - description: 'Dev', - category: 'cloud', filters: [{ key: 'cloud', value: 'dev', operator: 'equals' }], }, }, @@ -27,9 +21,6 @@ export const mocksScopes: Scope[] = [ metadata: { name: 'ops' }, spec: { title: 'Ops', - type: 'cloud', - description: 'Ops', - category: 'cloud', filters: [{ key: 'cloud', value: 'ops', operator: 'equals' }], }, }, @@ -37,9 +28,6 @@ export const mocksScopes: Scope[] = [ metadata: { name: 'prod' }, spec: { title: 'Prod', - type: 'cloud', - description: 'Prod', - category: 'cloud', filters: [{ key: 'cloud', value: 'prod', operator: 'equals' }], }, }, @@ -47,9 +35,6 @@ export const mocksScopes: Scope[] = [ metadata: { name: 'grafana' }, spec: { title: 'Grafana', - type: 'app', - description: 'Grafana', - category: 'apps', filters: [{ key: 'app', value: 'grafana', operator: 'equals' }], }, }, @@ -57,9 +42,6 @@ export const mocksScopes: Scope[] = [ metadata: { name: 'mimir' }, spec: { title: 'Mimir', - type: 'app', - description: 'Mimir', - category: 'apps', filters: [{ key: 'app', value: 'mimir', operator: 'equals' }], }, }, @@ -67,9 +49,6 @@ export const mocksScopes: Scope[] = [ metadata: { name: 'loki' }, spec: { title: 'Loki', - type: 'app', - description: 'Loki', - category: 'apps', filters: [{ key: 'app', value: 'loki', operator: 'equals' }], }, }, @@ -77,9 +56,6 @@ export const mocksScopes: Scope[] = [ metadata: { name: 'tempo' }, spec: { title: 'Tempo', - type: 'app', - description: 'Tempo', - category: 'apps', filters: [{ key: 'app', value: 'tempo', operator: 'equals' }], }, }, diff --git a/public/app/features/scopes/utils.ts b/public/app/features/scopes/utils.ts index d86a6f69b02..b6badaa614a 100644 --- a/public/app/features/scopes/utils.ts +++ b/public/app/features/scopes/utils.ts @@ -6,9 +6,6 @@ export function getEmptyScopeObject(name: string, title?: string): Scope { spec: { filters: [], title: title || name, - type: '', - category: '', - description: '', }, }; }