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

Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
This commit is contained in:
Augustin Husson 2021-12-01 17:05:40 +01:00 committed by GitHub
parent 5a8e1474ed
commit ec002ae0dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 3 deletions

View file

@ -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`;
}

View file

@ -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 () => {

View file

@ -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 {