WIP
This commit is contained in:
@@ -63,7 +63,7 @@ func (s *legacyStorage) List(ctx context.Context, options *internalversion.ListO
|
||||
if options.FieldSelector != nil {
|
||||
for _, r := range options.FieldSelector.Requirements() {
|
||||
switch r.Field {
|
||||
case "spec.datasource.name":
|
||||
case "metadata.name":
|
||||
switch r.Operator {
|
||||
case selection.Equals, selection.DoubleEquals:
|
||||
uids = []string{r.Value}
|
||||
|
||||
@@ -20,5 +20,6 @@ export const correlationAPIv0alpha1 = generatedAPI.enhanceEndpoints({
|
||||
return originalQuery(requestOptions);
|
||||
};
|
||||
},
|
||||
// todo - do i add data massaging to list correlations here??
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
import { useAsyncFn } from 'react-use';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
|
||||
import { getDataSourceSrv, FetchResponse, CorrelationData, CorrelationsData } from '@grafana/runtime';
|
||||
import {
|
||||
getDataSourceSrv,
|
||||
FetchResponse,
|
||||
CorrelationData,
|
||||
CorrelationsData,
|
||||
config,
|
||||
CorrelationExternal,
|
||||
CorrelationQuery,
|
||||
} from '@grafana/runtime';
|
||||
import { correlationAPIv0alpha1 } from 'app/api/clients/correlations/v0alpha1';
|
||||
import { CorrelationList, Correlation as CorrelationK8s } from 'app/api/clients/correlations/v0alpha1/endpoints.gen';
|
||||
import { useGrafana } from 'app/core/context/GrafanaContext';
|
||||
|
||||
import {
|
||||
@@ -67,6 +77,33 @@ const toEnrichedCorrelationData = ({ sourceUID, ...correlation }: Correlation):
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const toEnrichedCorrelationDataK8s = (item: CorrelationK8s): CorrelationData | undefined => {
|
||||
if (item.metadata.name !== undefined) {
|
||||
const baseCor = {
|
||||
uid: item.metadata.name,
|
||||
sourceUID: item.spec.source.name, //todo
|
||||
label: item.spec.label,
|
||||
description: item.spec.description,
|
||||
provisioned: false, // todo
|
||||
type: item.spec.type,
|
||||
};
|
||||
|
||||
if (item.spec.type === 'external') {
|
||||
const extCorr: CorrelationExternal = {
|
||||
...baseCor,
|
||||
};
|
||||
return toEnrichedCorrelationData(extCorr);
|
||||
} else {
|
||||
const queryCorr: CorrelationQuery = {
|
||||
...baseCor,
|
||||
};
|
||||
return toEnrichedCorrelationData(queryCorr);
|
||||
}
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
const validSourceFilter = (correlation: CorrelationData | undefined): correlation is CorrelationData => !!correlation;
|
||||
|
||||
export const toEnrichedCorrelationsData = (correlationsResponse: CorrelationsResponse): CorrelationsData => {
|
||||
@@ -76,6 +113,13 @@ export const toEnrichedCorrelationsData = (correlationsResponse: CorrelationsRes
|
||||
};
|
||||
};
|
||||
|
||||
export const toEnrichedCorrelationDataK8s = (correlationsResponse: CorrelationList): CorrelationsData => {
|
||||
return {
|
||||
...correlationsResponse,
|
||||
correlations: correlationsResponse.items.map(toEnrichedCorrelationDataK8s).filter(validSourceFilter),
|
||||
};
|
||||
};
|
||||
|
||||
export function getData<T>(response: FetchResponse<T>) {
|
||||
return response.data;
|
||||
}
|
||||
@@ -90,17 +134,23 @@ export const useCorrelations = () => {
|
||||
const { backend } = useGrafana();
|
||||
|
||||
const [getInfo, get] = useAsyncFn<(params: GetCorrelationsParams) => Promise<CorrelationsData>>(
|
||||
(params) =>
|
||||
lastValueFrom(
|
||||
backend.fetch<CorrelationsResponse>({
|
||||
url: '/api/datasources/correlations',
|
||||
params: { page: params.page },
|
||||
method: 'GET',
|
||||
showErrorAlert: false,
|
||||
})
|
||||
)
|
||||
.then(getData)
|
||||
.then(toEnrichedCorrelationsData),
|
||||
(params) => {
|
||||
if (config.featureToggles.kubernetesCorrelations) {
|
||||
return toEnrichedCorrelationDataK8s(correlationAPIv0alpha1.endpoints.listCorrelation.select({}));
|
||||
} else {
|
||||
return lastValueFrom(
|
||||
backend.fetch<CorrelationsResponse>({
|
||||
url: '/api/datasources/correlations',
|
||||
params: { page: params.page },
|
||||
method: 'GET',
|
||||
showErrorAlert: false,
|
||||
})
|
||||
)
|
||||
.then(getData)
|
||||
.then(toEnrichedCorrelationsData);
|
||||
}
|
||||
},
|
||||
|
||||
[backend]
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user