Browse Source

extend the number of attribute check to know if it's a prometheusConfig (#9915)

Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
pull/9921/head
Augustin Husson 3 years ago committed by GitHub
parent
commit
ec002ae0dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      web/ui/module/codemirror-promql/src/client/prometheus.ts
  2. 31
      web/ui/module/codemirror-promql/src/complete/hybrid.test.ts
  3. 11
      web/ui/module/codemirror-promql/src/complete/index.ts

7
web/ui/module/codemirror-promql/src/client/prometheus.ts

@ -47,7 +47,7 @@ export interface CacheConfig {
}
export interface PrometheusConfig {
url: string;
url?: string;
lookbackInterval?: number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
httpErrorHandler?: (error: any) => void;
@ -84,7 +84,7 @@ export class HTTPPrometheusClient implements PrometheusClient {
private readonly fetchFn: FetchFn = (input: RequestInfo, init?: RequestInit): Promise<Response> => fetch(input, init);
constructor(config: PrometheusConfig) {
this.url = config.url;
this.url = config.url ? config.url : '';
this.errorHandler = config.httpErrorHandler;
if (config.lookbackInterval) {
this.lookbackInterval = config.lookbackInterval;
@ -242,12 +242,15 @@ export class HTTPPrometheusClient implements PrometheusClient {
private labelsEndpoint(): string {
return `${this.apiPrefix}/labels`;
}
private labelValuesEndpoint(): string {
return `${this.apiPrefix}/label/:name/values`;
}
private seriesEndpoint(): string {
return `${this.apiPrefix}/series`;
}
private metricMetadataEndpoint(): string {
return `${this.apiPrefix}/metadata`;
}

31
web/ui/module/codemirror-promql/src/complete/hybrid.test.ts

@ -1247,6 +1247,37 @@ describe('autocomplete promQL test', () => {
span: /^[a-zA-Z0-9_:]+$/,
},
},
{
title: 'online autocomplete with initial metric list',
expr: 'rat',
pos: 3,
conf: { remote: { cache: { initialMetricList: ['metric1', 'metric2', 'rat'] } } },
expectedResult: {
options: ([] as Completion[]).concat(
[
{
label: 'metric1',
type: 'constant',
},
{
label: 'metric2',
type: 'constant',
},
{
label: 'rat',
type: 'constant',
},
],
functionIdentifierTerms,
aggregateOpTerms,
numberTerms,
snippets
),
from: 0,
to: 3,
span: /^[a-zA-Z0-9_:]+$/,
},
},
];
testCases.forEach((value) => {
it(value.title, async () => {

11
web/ui/module/codemirror-promql/src/complete/index.ts

@ -32,7 +32,16 @@ export interface CompleteConfiguration {
}
function isPrometheusConfig(remoteConfig: PrometheusConfig | PrometheusClient): remoteConfig is PrometheusConfig {
return (remoteConfig as PrometheusConfig).url !== undefined;
const cfg = remoteConfig as PrometheusConfig;
return (
cfg.url !== undefined ||
cfg.lookbackInterval !== undefined ||
cfg.httpErrorHandler !== undefined ||
cfg.fetchFn !== undefined ||
cfg.cache !== undefined ||
cfg.httpMethod !== undefined ||
cfg.apiPrefix !== undefined
);
}
export function newCompleteStrategy(conf?: CompleteConfiguration): CompleteStrategy {

Loading…
Cancel
Save