mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Remove redundant code and update types (#76489)
Remove redundant code and update types
This commit is contained in:
@@ -6706,7 +6706,7 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "10"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "11"]
|
||||
],
|
||||
"public/app/plugins/datasource/prometheus/datasource.tsx:5381": [
|
||||
"public/app/plugins/datasource/prometheus/datasource.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
|
||||
|
||||
@@ -13,10 +13,9 @@ import { getBackendSrv } from '@grafana/runtime/src';
|
||||
import { InlineField, Input, Select, Switch, useTheme2 } from '@grafana/ui';
|
||||
|
||||
import { useUpdateDatasource } from '../../../../features/datasources/state';
|
||||
import { PromApplication, PromBuildInfoResponse } from '../../../../types/unified-alerting-dto';
|
||||
import { QueryEditorMode } from '../querybuilder/shared/types';
|
||||
import { defaultPrometheusQueryOverlapWindow } from '../querycache/QueryCache';
|
||||
import { PrometheusCacheLevel, PromOptions } from '../types';
|
||||
import { PromApplication, PromBuildInfoResponse, PrometheusCacheLevel, PromOptions } from '../types';
|
||||
|
||||
import { docsTip, overhaulStyles, PROM_CONFIG_LABEL_WIDTH, validateInput } from './ConfigEditor';
|
||||
import { ExemplarsSettings } from './ExemplarsSettings';
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { cloneDeep, defaults } from 'lodash';
|
||||
import { LRUCache } from 'lru-cache';
|
||||
import React from 'react';
|
||||
import { forkJoin, lastValueFrom, merge, Observable, of, OperatorFunction, pipe, throwError } from 'rxjs';
|
||||
import { catchError, filter, map, tap } from 'rxjs/operators';
|
||||
import semver from 'semver/preload';
|
||||
|
||||
import {
|
||||
AbstractQuery,
|
||||
AdHocVariableFilter,
|
||||
AnnotationEvent,
|
||||
AnnotationQueryRequest,
|
||||
CoreApp,
|
||||
@@ -14,20 +13,19 @@ import {
|
||||
DataQueryError,
|
||||
DataQueryRequest,
|
||||
DataQueryResponse,
|
||||
DataSourceGetTagKeysOptions,
|
||||
DataSourceGetTagValuesOptions,
|
||||
DataSourceInstanceSettings,
|
||||
DataSourceWithQueryExportSupport,
|
||||
DataSourceWithQueryImportSupport,
|
||||
dateTime,
|
||||
LoadingState,
|
||||
MetricFindValue,
|
||||
QueryFixAction,
|
||||
rangeUtil,
|
||||
renderLegendFormat,
|
||||
ScopedVars,
|
||||
TimeRange,
|
||||
renderLegendFormat,
|
||||
DataSourceGetTagKeysOptions,
|
||||
DataSourceGetTagValuesOptions,
|
||||
MetricFindValue,
|
||||
AdHocVariableFilter,
|
||||
} from '@grafana/data';
|
||||
import {
|
||||
BackendDataSourceResponse,
|
||||
@@ -39,12 +37,9 @@ import {
|
||||
isFetchError,
|
||||
toDataQueryResponse,
|
||||
} from '@grafana/runtime';
|
||||
import { Badge, BadgeColor, Tooltip } from '@grafana/ui';
|
||||
import { safeStringifyValue } from 'app/core/utils/explore';
|
||||
import { discoverDataSourceFeatures } from 'app/features/alerting/unified/api/buildInfo';
|
||||
import { getTimeSrv, TimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
||||
import { getTemplateSrv, TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { PromApiFeatures, PromApplication } from 'app/types/unified-alerting-dto';
|
||||
|
||||
import { addLabelToQuery } from './add_label_to_query';
|
||||
import { AnnotationQueryEditor } from './components/AnnotationQueryEditor';
|
||||
@@ -64,6 +59,7 @@ import { getOriginalMetricName, transform, transformV2 } from './result_transfor
|
||||
import { trackQuery } from './tracking';
|
||||
import {
|
||||
ExemplarTraceIdDestination,
|
||||
PromApplication,
|
||||
PromDataErrorResponse,
|
||||
PromDataSuccessResponse,
|
||||
PrometheusCacheLevel,
|
||||
@@ -95,7 +91,6 @@ export class PrometheusDatasource
|
||||
access: 'direct' | 'proxy';
|
||||
basicAuth: any;
|
||||
withCredentials: any;
|
||||
metricsNameCache = new LRUCache<string, string[]>({ max: 10 });
|
||||
interval: string;
|
||||
queryTimeout: string | undefined;
|
||||
httpMethod: string;
|
||||
@@ -108,8 +103,6 @@ export class PrometheusDatasource
|
||||
disableRecordingRules: boolean;
|
||||
defaultEditor?: QueryEditorMode;
|
||||
exemplarsAvailable: boolean;
|
||||
subType: PromApplication;
|
||||
rulerEnabled: boolean;
|
||||
cacheLevel: PrometheusCacheLevel;
|
||||
cache: QueryCache<PromQuery>;
|
||||
|
||||
@@ -122,8 +115,6 @@ export class PrometheusDatasource
|
||||
super(instanceSettings);
|
||||
|
||||
this.type = 'prometheus';
|
||||
this.subType = PromApplication.Prometheus;
|
||||
this.rulerEnabled = false;
|
||||
this.id = instanceSettings.id;
|
||||
this.url = instanceSettings.url!;
|
||||
this.access = instanceSettings.access;
|
||||
@@ -481,10 +472,6 @@ export class PrometheusDatasource
|
||||
return processedTargets;
|
||||
}
|
||||
|
||||
intepolateStringHelper = (query: PromQuery): string => {
|
||||
return this.interpolateString(query.expr);
|
||||
};
|
||||
|
||||
query(request: DataQueryRequest<PromQuery>): Observable<DataQueryResponse> {
|
||||
if (this.access === 'proxy') {
|
||||
let fullOrPartialRequest: DataQueryRequest<PromQuery>;
|
||||
@@ -1023,94 +1010,6 @@ export class PrometheusDatasource
|
||||
return result?.data?.data?.map((value: any) => ({ text: value })) ?? [];
|
||||
}
|
||||
|
||||
async getBuildInfo() {
|
||||
try {
|
||||
const buildInfo = await discoverDataSourceFeatures({ url: this.url, name: this.name, type: 'prometheus' });
|
||||
return buildInfo;
|
||||
} catch (error) {
|
||||
// We don't want to break the rest of functionality if build info does not work correctly
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
getBuildInfoMessage(buildInfo: PromApiFeatures) {
|
||||
const enabled = <Badge color="green" icon="check" text="Ruler API enabled" />;
|
||||
const disabled = <Badge color="orange" icon="exclamation-triangle" text="Ruler API not enabled" />;
|
||||
const unsupported = (
|
||||
<Tooltip
|
||||
placement="top"
|
||||
content="Prometheus does not allow editing rules, connect to either a Mimir or Cortex datasource to manage alerts via Grafana."
|
||||
>
|
||||
<div>
|
||||
<Badge color="red" icon="exclamation-triangle" text="Ruler API not supported" />
|
||||
</div>
|
||||
</Tooltip>
|
||||
);
|
||||
|
||||
const LOGOS = {
|
||||
[PromApplication.Cortex]: '/public/app/plugins/datasource/prometheus/img/cortex_logo.svg',
|
||||
[PromApplication.Mimir]: '/public/app/plugins/datasource/prometheus/img/mimir_logo.svg',
|
||||
[PromApplication.Prometheus]: '/public/app/plugins/datasource/prometheus/img/prometheus_logo.svg',
|
||||
[PromApplication.Thanos]: '/public/app/plugins/datasource/prometheus/img/thanos_logo.svg',
|
||||
};
|
||||
|
||||
const COLORS: Record<PromApplication, BadgeColor> = {
|
||||
[PromApplication.Cortex]: 'blue',
|
||||
[PromApplication.Mimir]: 'orange',
|
||||
[PromApplication.Prometheus]: 'red',
|
||||
[PromApplication.Thanos]: 'purple', // Purple hex taken from thanos.io
|
||||
};
|
||||
|
||||
const AppDisplayNames: Record<PromApplication, string> = {
|
||||
[PromApplication.Cortex]: 'Cortex',
|
||||
[PromApplication.Mimir]: 'Mimir',
|
||||
[PromApplication.Prometheus]: 'Prometheus',
|
||||
[PromApplication.Thanos]: 'Thanos',
|
||||
};
|
||||
|
||||
const application = this.datasourceConfigurationPrometheusFlavor ?? buildInfo.application;
|
||||
|
||||
// this will inform the user about what "subtype" the datasource is; Mimir, Cortex or vanilla Prometheus
|
||||
const applicationSubType = (
|
||||
<Badge
|
||||
text={
|
||||
<span>
|
||||
<img
|
||||
style={{ width: 14, height: 14, verticalAlign: 'text-bottom' }}
|
||||
src={LOGOS[application ?? PromApplication.Prometheus]}
|
||||
alt=""
|
||||
/>{' '}
|
||||
{application ? AppDisplayNames[application] : 'Unknown'}
|
||||
</span>
|
||||
}
|
||||
color={COLORS[application ?? PromApplication.Prometheus]}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: 'max-content max-content',
|
||||
rowGap: '0.5rem',
|
||||
columnGap: '2rem',
|
||||
marginTop: '1rem',
|
||||
}}
|
||||
>
|
||||
<div>Type</div>
|
||||
<div>{applicationSubType}</div>
|
||||
<>
|
||||
<div>Ruler API</div>
|
||||
{/* Prometheus does not have a Ruler API – so show that it is not supported */}
|
||||
{buildInfo.application === PromApplication.Prometheus && <div>{unsupported}</div>}
|
||||
{buildInfo.application !== PromApplication.Prometheus && (
|
||||
<div>{buildInfo.features.rulerApiEnabled ? enabled : disabled}</div>
|
||||
)}
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
interpolateVariablesInQueries(
|
||||
queries: PromQuery[],
|
||||
scopedVars: ScopedVars,
|
||||
@@ -6,11 +6,9 @@ import { FetchResponse } from '@grafana/runtime';
|
||||
import { backendSrv } from 'app/core/services/backend_srv'; // will use the version in __mocks__
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
|
||||
import { PromApplication } from '../../../types/unified-alerting-dto';
|
||||
|
||||
import { PrometheusDatasource } from './datasource';
|
||||
import PrometheusMetricFindQuery from './metric_find_query';
|
||||
import { PromOptions } from './types';
|
||||
import { PromApplication, PromOptions } from './types';
|
||||
|
||||
jest.mock('@grafana/runtime', () => ({
|
||||
...jest.requireActual('@grafana/runtime'),
|
||||
|
||||
@@ -12,11 +12,10 @@ import {
|
||||
TimeRange,
|
||||
} from '@grafana/data';
|
||||
|
||||
import { PromApplication } from '../../../../../types/unified-alerting-dto';
|
||||
import { PrometheusDatasource } from '../../datasource';
|
||||
import PromQlLanguageProvider from '../../language_provider';
|
||||
import { EmptyLanguageProviderMock } from '../../language_provider.mock';
|
||||
import { PromOptions } from '../../types';
|
||||
import { PromApplication, PromOptions } from '../../types';
|
||||
import { getLabelSelects } from '../testUtils';
|
||||
import { PromVisualQuery } from '../types';
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { DataSourceJsonData, QueryResultMeta, ScopedVars } from '@grafana/data';
|
||||
import { DataQuery } from '@grafana/schema';
|
||||
|
||||
import { PromApplication } from '../../../types/unified-alerting-dto';
|
||||
|
||||
import { Prometheus as GenPromQuery } from './dataquery.gen';
|
||||
import { QueryBuilderLabelFilter, QueryEditorMode } from './querybuilder/shared/types';
|
||||
|
||||
@@ -30,6 +28,13 @@ export enum PrometheusCacheLevel {
|
||||
None = 'None',
|
||||
}
|
||||
|
||||
export enum PromApplication {
|
||||
Cortex = 'Cortex',
|
||||
Mimir = 'Mimir',
|
||||
Prometheus = 'Prometheus',
|
||||
Thanos = 'Thanos',
|
||||
}
|
||||
|
||||
export interface PromOptions extends DataSourceJsonData {
|
||||
timeInterval?: string;
|
||||
queryTimeout?: string;
|
||||
@@ -159,12 +164,20 @@ export interface TransformOptions {
|
||||
meta: QueryResultMeta;
|
||||
}
|
||||
|
||||
export interface PromLabelQueryResponse {
|
||||
export interface PromBuildInfoResponse {
|
||||
data: {
|
||||
status: string;
|
||||
data: string[];
|
||||
application?: string;
|
||||
version: string;
|
||||
revision: string;
|
||||
features?: {
|
||||
ruler_config_api?: 'true' | 'false';
|
||||
alertmanager_config_api?: 'true' | 'false';
|
||||
query_sharding?: 'true' | 'false';
|
||||
federated_rules?: 'true' | 'false';
|
||||
};
|
||||
[key: string]: unknown;
|
||||
};
|
||||
cancelled?: boolean;
|
||||
status: 'success';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user