Kindsys: Unify plugins, pfs with kind framework (#61192)

* New pfs impl

* Reached codegen parity with old system

* Update all models.cue inputs

* Rename all models.cue files

* Remove unused prefixfs

* Changes Queries->DataQuery schema interface

* Recodegen

* All tests passing, nearly good now

* Add SchemaInterface to kindsys props

* Add pascal name deriver

* Relocate plugin cue files again

* Clarify use of injected fields

* Remove unnecessary aliasing

* Move DataQuery into mudball

* Allow forcing ExpandReferences on go type generation

* Move DataQuery def into kindsys, add generator to copy it to common

* Fix copy generator to replace package name correctly

* Fix duplicate type, test failure

* Fix linting issues
This commit is contained in:
sam boyer
2023-01-20 04:41:35 -05:00
committed by GitHub
parent 6a7cbeae6c
commit 3b3059c9ce
91 changed files with 2192 additions and 1870 deletions

View File

@@ -1,3 +1,15 @@
import { DataQuery as SchemaDataQuery, DataSourceRef as SchemaDataSourceRef } from '@grafana/schema';
/**
* @deprecated use the type from @grafana/schema
*/
export interface DataQuery extends SchemaDataQuery {}
/**
* @deprecated use the type from @grafana/schema
*/
export interface DataSourceRef extends SchemaDataSourceRef {}
/**
* Attached to query results (not persisted)
*
@@ -7,57 +19,11 @@ export enum DataTopic {
Annotations = 'annotations',
}
/**
* @public
*/
export interface DataSourceRef {
/** The plugin type-id */
type?: string;
/** Specific datasource instance */
uid?: string;
}
/**
* These are the common properties available to all queries in all datasources
* Specific implementations will *extend* this interface adding the required properties
* for the given context
*
* @public
*/
export interface DataQuery {
/**
* A - Z
*/
refId: string;
/**
* true if query is disabled (ie should not be returned to the dashboard)
*/
hide?: boolean;
/**
* Unique, guid like, string used in explore mode
*/
key?: string;
/**
* Specify the query flavor
*/
queryType?: string;
/**
* For mixed data sources the selected datasource is on the query level.
* For non mixed scenarios this is undefined.
*/
datasource?: DataSourceRef | null;
}
/**
* Abstract representation of any label-based query
* @internal
*/
export interface AbstractQuery extends DataQuery {
export interface AbstractQuery extends SchemaDataQuery {
labelMatchers: AbstractLabelMatcher[];
}
@@ -83,21 +49,21 @@ export type AbstractLabelMatcher = {
/**
* @internal
*/
export interface DataSourceWithQueryImportSupport<TQuery extends DataQuery> {
export interface DataSourceWithQueryImportSupport<TQuery extends SchemaDataQuery> {
importFromAbstractQueries(labelBasedQuery: AbstractQuery[]): Promise<TQuery[]>;
}
/**
* @internal
*/
export interface DataSourceWithQueryExportSupport<TQuery extends DataQuery> {
export interface DataSourceWithQueryExportSupport<TQuery extends SchemaDataQuery> {
exportToAbstractQueries(query: TQuery[]): Promise<AbstractQuery[]>;
}
/**
* @internal
*/
export const hasQueryImportSupport = <TQuery extends DataQuery>(
export const hasQueryImportSupport = <TQuery extends SchemaDataQuery>(
datasource: unknown
): datasource is DataSourceWithQueryImportSupport<TQuery> => {
return (datasource as DataSourceWithQueryImportSupport<TQuery>).importFromAbstractQueries !== undefined;
@@ -106,7 +72,7 @@ export const hasQueryImportSupport = <TQuery extends DataQuery>(
/**
* @internal
*/
export const hasQueryExportSupport = <TQuery extends DataQuery>(
export const hasQueryExportSupport = <TQuery extends SchemaDataQuery>(
datasource: unknown
): datasource is DataSourceWithQueryExportSupport<TQuery> => {
return (datasource as DataSourceWithQueryExportSupport<TQuery>).exportToAbstractQueries !== undefined;

View File

@@ -8,6 +8,38 @@
// Run 'make gen-cue' from repository root to regenerate.
/**
* These are the common properties available to all queries in all datasources.
* Specific implementations will *extend* this interface, adding the required
* properties for the given context.
*/
export interface DataQuery {
/**
* For mixed data sources the selected datasource is on the query level.
* For non mixed scenarios this is undefined.
* TODO find a better way to do this ^ that's friendly to schema
* TODO this shouldn't be unknown but DataSourceRef | null
*/
datasource?: unknown;
/**
* true if query is disabled (ie should not be returned to the dashboard)
*/
hide?: boolean;
/**
* Unique, guid like, string used in explore mode
*/
key?: string;
/**
* Specify the query flavor
* TODO make this required and give it a default
*/
queryType?: string;
/**
* A - Z
*/
refId: string;
}
/**
* TODO docs
*/
@@ -552,6 +584,17 @@ export type TimeZoneUtc = 'utc';
*/
export type TimeZoneBrowser = 'browser';
export interface DataSourceRef {
/**
* The plugin type-id
*/
type?: string;
/**
* Specific datasource instance
*/
uid?: string;
}
/**
* TODO docs
*/

View File

@@ -0,0 +1,46 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
//
// Generated by:
// kinds/gen.go
// Using jennies:
// CommonSchemaJenny
//
// Run 'make gen-cue' from repository root to regenerate.
package common
// Canonically defined in pkg/kindsys/dataquery.cue FOR NOW to avoid having any external imports
// in kindsys. Code generation copies this file to the common schemas in packages/grafana-schema/src/common.
//
// NOTE make gen-cue must be run twice when updating this file
// These are the common properties available to all queries in all datasources.
// Specific implementations will *extend* this interface, adding the required
// properties for the given context.
DataQuery: {
// A - Z
refId: string
// true if query is disabled (ie should not be returned to the dashboard)
hide?: bool
// Unique, guid like, string used in explore mode
key?: string
// Specify the query flavor
// TODO make this required and give it a default
queryType?: string
// For mixed data sources the selected datasource is on the query level.
// For non mixed scenarios this is undefined.
// TODO find a better way to do this ^ that's friendly to schema
// TODO this shouldn't be unknown but DataSourceRef | null
datasource?: _
} @cuetsy(kind="interface")
DataSourceRef: {
// The plugin type-id
type?: string
// Specific datasource instance
uid?: string
} @cuetsy(kind="interface")

View File

@@ -246,3 +246,5 @@ VizTooltipOptions: {
mode: TooltipDisplayMode
sort: SortOrder
} @cuetsy(kind="interface")

View File

@@ -11,7 +11,6 @@
export type {
AnnotationTarget,
AnnotationQuery,
DataSourceRef,
DashboardLink,
DashboardLinkType,
VariableType,
@@ -63,6 +62,7 @@ export {
export type {
Dashboard,
VariableModel,
DataSourceRef,
Panel,
FieldConfigSource,
FieldConfig

View File

@@ -3,5 +3,5 @@
*
* @packageDocumentation
*/
export * from './common/common.gen';
export * from './veneer/common.types';
export * from './index.gen';

View File

@@ -0,0 +1,8 @@
import * as raw from '../common/common.gen';
export interface DataQuery extends raw.DataQuery {
// TODO remove explicit nulls
datasource?: raw.DataSourceRef | null;
}
export * from '../common/common.gen';

View File

@@ -1,5 +1,8 @@
import { DataSourceRef as CommonDataSourceRef } from '../common/common.gen';
import * as raw from '../raw/dashboard/x/dashboard_types.gen';
export type { CommonDataSourceRef as DataSourceRef };
export interface Panel<TOptions = Record<string, unknown>, TCustomFieldConfig = Record<string, unknown>>
extends raw.Panel {
fieldConfig: FieldConfigSource<TCustomFieldConfig>;
@@ -14,11 +17,15 @@ export enum VariableHide {
export interface VariableModel
extends Omit<raw.VariableModel, 'rootStateKey' | 'error' | 'description' | 'hide' | 'datasource'> {
// Overrides nullable properties because CUE doesn't support null values
// TODO remove explicit nulls
rootStateKey: string | null;
// TODO remove explicit nulls
error: any | null;
// TODO remove explicit nulls
description: string | null;
hide: VariableHide;
datasource: raw.DataSourceRef | null;
// TODO remove explicit nulls
datasource: CommonDataSourceRef | null;
}
export interface Dashboard extends Omit<raw.Dashboard, 'templating'> {
@@ -39,11 +46,15 @@ export interface FieldConfigSource<TOptions = Record<string, unknown>> extends r
export const defaultDashboard = raw.defaultDashboard as Dashboard;
export const defaultVariableModel = {
...raw.defaultVariableModel,
// TODO remove explicit nulls
rootStateKey: null,
// TODO remove explicit nulls
error: null,
// TODO remove explicit nulls
description: null,
hide: VariableHide.dontHide,
state: raw.LoadingState.NotStarted,
// TODO remove explicit nulls
datasource: null,
} as VariableModel;
export const defaultPanel: Partial<Panel> = raw.defaultPanel;