mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
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:
parent
5a8e1474ed
commit
ec002ae0dc
|
@ -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`;
|
||||
}
|
||||
|
|
|
@ -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 () => {
|
||||
|
|
|
@ -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…
Reference in a new issue