Prometheus: Add Victoria metrics to Prometheus type dropdown in datasource config (#66984)

* add VictoriaMetrics to prometheus type dropdown
This commit is contained in:
Galen Kistler
2023-04-21 09:12:28 -05:00
committed by GitHub
parent b6953763f4
commit 7cb4d65584
7 changed files with 70 additions and 47 deletions

View File

@@ -77,4 +77,15 @@ export const PromFlavorVersions: { [index: string]: Array<{ value?: string; labe
{ value: '1.13.0', label: '1.13.x' },
{ value: '1.14.0', label: '> 1.13.x' },
],
VictoriaMetrics: [
{ value: '1.23.0', label: '< 1.24.0' },
{ value: '1.24.0', label: '>= 1.24.x' },
{ value: '1.30.0', label: '1.3x' },
{ value: '1.40.0', label: '1.4x' },
{ value: '1.50.0', label: '1.5x' },
{ value: '1.60.0', label: '1.6x' },
{ value: '1.70.0', label: '1.7x' },
{ value: '1.80.0', label: '1.8x' },
{ value: '1.90.0', label: '>= 1.9x' },
],
};

View File

@@ -56,6 +56,7 @@ const prometheusFlavorSelectItems: PrometheusSelectItemsType = [
{ value: PromApplication.Cortex, label: PromApplication.Cortex },
{ value: PromApplication.Mimir, label: PromApplication.Mimir },
{ value: PromApplication.Thanos, label: PromApplication.Thanos },
{ value: PromApplication.VictoriaMetrics, label: PromApplication.VictoriaMetrics },
];
type Props = Pick<DataSourcePluginOptionsEditorProps<PromOptions>, 'options' | 'onOptionsChange'>;
@@ -118,32 +119,37 @@ const setPrometheusVersion = (
// This will save the current state of the form, as the url is needed for this API call to function
onUpdate(options)
.then((updatedOptions) => {
getBackendSrv()
.get(`/api/datasources/uid/${updatedOptions.uid}/resources/version-detect`)
.then((rawResponse: PromBuildInfoResponse) => {
const rawVersionStringFromApi = rawResponse.data?.version ?? '';
if (rawVersionStringFromApi && semver.valid(rawVersionStringFromApi)) {
const parsedVersion = getVersionString(rawVersionStringFromApi, updatedOptions.jsonData.prometheusType);
// If we got a successful response, let's update the backend with the version right away if it's new
if (parsedVersion) {
onUpdate({
...updatedOptions,
jsonData: {
...updatedOptions.jsonData,
prometheusVersion: parsedVersion,
},
}).then((updatedUpdatedOptions) => {
onOptionsChange(updatedUpdatedOptions);
});
// Not seeing version info in buildinfo response from VictoriaMetrics, and Cortex doesn't support yet, users will need to manually select version
if (
updatedOptions.jsonData.prometheusType !== PromApplication.VictoriaMetrics &&
updatedOptions.jsonData.prometheusType !== PromApplication.Cortex
) {
getBackendSrv()
.get(`/api/datasources/uid/${updatedOptions.uid}/resources/version-detect`)
.then((rawResponse: PromBuildInfoResponse) => {
const rawVersionStringFromApi = rawResponse.data?.version ?? '';
if (rawVersionStringFromApi && semver.valid(rawVersionStringFromApi)) {
const parsedVersion = getVersionString(rawVersionStringFromApi, updatedOptions.jsonData.prometheusType);
// If we got a successful response, let's update the backend with the version right away if it's new
if (parsedVersion) {
onUpdate({
...updatedOptions,
jsonData: {
...updatedOptions.jsonData,
prometheusVersion: parsedVersion,
},
}).then((updatedUpdatedOptions) => {
onOptionsChange(updatedUpdatedOptions);
});
}
} else {
unableToDeterminePrometheusVersion();
}
} else {
unableToDeterminePrometheusVersion();
}
});
})
.catch(unableToDeterminePrometheusVersion);
}
})
.catch((error) => {
unableToDeterminePrometheusVersion(error);
});
.catch(unableToDeterminePrometheusVersion);
};
export const PromSettings = (props: Props) => {

View File

@@ -173,6 +173,8 @@ export class PrometheusDatasource
this._isDatasourceVersionGreaterOrEqualTo('2.0.0', PromApplication.Mimir) ||
// https://github.com/cortexproject/cortex/discussions/4542
this._isDatasourceVersionGreaterOrEqualTo('1.11.0', PromApplication.Cortex) ||
//https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.24.0
this._isDatasourceVersionGreaterOrEqualTo('1.24.0', PromApplication.VictoriaMetrics) ||
// https://github.com/thanos-io/thanos/pull/3566
//https://github.com/thanos-io/thanos/releases/tag/v0.18.0
this._isDatasourceVersionGreaterOrEqualTo('0.18.0', PromApplication.Thanos)
@@ -992,6 +994,7 @@ export class PrometheusDatasource
[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',
[PromApplication.VictoriaMetrics]: '/public/app/plugins/datasource/prometheus/img/vm_logo.svg',
};
const COLORS: Record<PromApplication, BadgeColor> = {
@@ -999,6 +1002,7 @@ export class PrometheusDatasource
[PromApplication.Mimir]: 'orange',
[PromApplication.Prometheus]: 'red',
[PromApplication.Thanos]: 'purple', // Purple hex taken from thanos.io
[PromApplication.VictoriaMetrics]: 'black',
};
const AppDisplayNames: Record<PromApplication, string> = {
@@ -1006,6 +1010,7 @@ export class PrometheusDatasource
[PromApplication.Mimir]: 'Mimir',
[PromApplication.Prometheus]: 'Prometheus',
[PromApplication.Thanos]: 'Thanos',
[PromApplication.VictoriaMetrics]: 'VictoriaMetrics',
};
const application = this.datasourceConfigurationPrometheusFlavor ?? buildInfo.application;

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB