Skip to content

Commit 18d0655

Browse files
committed
remove automatic flavor and version detection
1 parent e703d1f commit 18d0655

File tree

1 file changed

+1
-114
lines changed

1 file changed

+1
-114
lines changed

src/configuration/PromSettings.tsx

Lines changed: 1 addition & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
import {
22
DataSourcePluginOptionsEditorProps,
3-
/* DataSourceSettings as DataSourceSettingsType, */
43
onUpdateDatasourceJsonDataOptionChecked,
54
SelectableValue,
65
updateDatasourcePluginJsonDataOption,
76
} from '@grafana/data';
87
import { ConfigSubSection } from '@grafana/experimental';
9-
// import { config/*, getBackendSrv */} from '@grafana/runtime';
108
import { InlineField, Input, Select, Switch, useTheme2 } from '@grafana/ui';
119
import React, { SyntheticEvent, useState } from 'react';
12-
// import semver from 'semver/preload';
1310

14-
15-
// import { useUpdateDatasource } from '../../../../features/datasources/state';
16-
// import { PromApplication, PromBuildInfoResponse } from '../../../../types/unified-alerting-dto';
1711
import { QueryEditorMode } from '../querybuilder/shared/types';
1812
import { defaultPrometheusQueryOverlapWindow } from '../querycache/QueryCache';
19-
import { PromApplication, /*PromBuildInfoResponse,*/ PrometheusCacheLevel, PromOptions } from '../types';
13+
import { PromApplication, PrometheusCacheLevel, PromOptions } from '../types';
2014

2115
import { docsTip, overhaulStyles, PROM_CONFIG_LABEL_WIDTH, validateInput } from './ConfigEditor';
2216
import { ExemplarsSettings } from './ExemplarsSettings';
@@ -57,108 +51,17 @@ export const DURATION_REGEX = /^$|^\d+(ms|[Mwdhmsy])$/;
5751
export const MULTIPLE_DURATION_REGEX = /(\d+)(.+)/;
5852

5953
const durationError = 'Value is not valid, you can use number with time unit specifier: y, M, w, d, h, m, s';
60-
/**
61-
* Returns the closest version to what the user provided that we have in our PromFlavorVersions for the currently selected flavor
62-
* Bugs: It will only reject versions that are a major release apart, so Mimir 2.x might get selected for Prometheus 2.8 if the user selects an incorrect flavor
63-
* Advantages: We don't need to maintain a list of every possible version for each release
64-
*
65-
* This function will return the closest version from PromFlavorVersions that is equal or lower to the version argument
66-
*/
67-
// const getVersionString = (version: string, flavor?: string): string | undefined => {
68-
// if (!flavor || !PromFlavorVersions[flavor]) {
69-
// return;
70-
// }
71-
// const flavorVersionValues = PromFlavorVersions[flavor];
72-
73-
// // As long as it's assured we're using versions which are sorted, we could just filter out the values greater than the target version, and then check the last element in the array
74-
// const versionsLessThanOrEqual = flavorVersionValues
75-
// ?.filter((el) => !!el.value && semver.lte(el.value, version))
76-
// .map((el) => el.value);
77-
78-
// const closestVersion = versionsLessThanOrEqual[versionsLessThanOrEqual.length - 1];
79-
80-
// if (closestVersion) {
81-
// const differenceBetweenActualAndClosest = semver.diff(closestVersion, version);
82-
83-
// // Only return versions if the target is close to the actual.
84-
// if (['patch', 'prepatch', 'prerelease', null].includes(differenceBetweenActualAndClosest)) {
85-
// return closestVersion;
86-
// }
87-
// }
88-
89-
// return;
90-
// };
91-
92-
// const unableToDeterminePrometheusVersion = (error?: Error): void => {
93-
// console.warn('Error fetching version from buildinfo API, must manually select version!', error);
94-
// };
95-
96-
/**
97-
* I don't like the daisy chain of network requests, and that we have to save on behalf of the user, but currently
98-
* the backend doesn't allow for the prometheus client url to be passed in from the frontend, so we currently need to save it
99-
* to the database before consumption.
100-
*
101-
* Since the prometheus version fields are below the url field, we can expect users to populate this field before
102-
* hitting save and test at the bottom of the page. For this case we need to save the current fields before calling the
103-
* resource to auto-detect the version.
104-
*
105-
* @param options
106-
* @param onOptionsChange
107-
* @param onUpdate
108-
*/
109-
// COMMENTING OUT UNTIL WE CAN FIGURE OUT HOW TO DO THIS OUTSIDE OF CORE
110-
// const setPrometheusVersion = (
111-
// options: DataSourceSettingsType<PromOptions>,
112-
// onOptionsChange: (options: DataSourceSettingsType<PromOptions>) => void,
113-
// onUpdate: (dataSource: DataSourceSettingsType<PromOptions>) => Promise<DataSourceSettingsType<PromOptions>>
114-
// ) => {
115-
// // This will save the current state of the form, as the url is needed for this API call to function
116-
// onUpdate(options)
117-
// .then((updatedOptions) => {
118-
// getBackendSrv()
119-
// .get(`/api/datasources/uid/${updatedOptions.uid}/resources/version-detect`)
120-
// .then((rawResponse: PromBuildInfoResponse) => {
121-
// const rawVersionStringFromApi = rawResponse.data?.version ?? '';
122-
// if (rawVersionStringFromApi && semver.valid(rawVersionStringFromApi)) {
123-
// const parsedVersion = getVersionString(rawVersionStringFromApi, updatedOptions.jsonData.prometheusType);
124-
// // If we got a successful response, let's update the backend with the version right away if it's new
125-
// if (parsedVersion) {
126-
// onUpdate({
127-
// ...updatedOptions,
128-
// jsonData: {
129-
// ...updatedOptions.jsonData,
130-
// prometheusVersion: parsedVersion,
131-
// },
132-
// }).then((updatedUpdatedOptions) => {
133-
// onOptionsChange(updatedUpdatedOptions);
134-
// });
135-
// }
136-
// } else {
137-
// unableToDeterminePrometheusVersion();
138-
// }
139-
// });
140-
// })
141-
// .catch((error) => {
142-
// unableToDeterminePrometheusVersion(error);
143-
// });
144-
// };
14554

14655
export const PromSettings = (props: Props) => {
14756
const { options, onOptionsChange } = props;
14857

149-
// This update call is typed as void, but it returns a response which we need
150-
// REMOVE UNTIL WE FIGURE OUT HOW TO DO THIS OUTSIDE OF CORE
151-
// const onUpdate = useUpdateDatasource();
152-
15358
// We are explicitly adding httpMethod so, it is correctly displayed in dropdown.
15459
// This way, it is more predictable for users.
15560
if (!options.jsonData.httpMethod) {
15661
options.jsonData.httpMethod = 'POST';
15762
}
15863

15964
const theme = useTheme2();
160-
// imported GrafanaTheme2 from @grafana/data does not match type of same from @grafana/ui
161-
// @ts-ignore
16265
const styles = overhaulStyles(theme);
16366

16467
type ValidDuration = {
@@ -328,22 +231,6 @@ export const PromSettings = (props: Props) => {
328231
aria-label="Prometheus type"
329232
options={prometheusFlavorSelectItems}
330233
value={prometheusFlavorSelectItems.find((o) => o.value === options.jsonData.prometheusType)}
331-
// REMOVE AUTO DETECT UNTIL WE CAN COME UP WITH A NON CORE SOLUTION
332-
// onChange={onChangeHandler(
333-
// 'prometheusType',
334-
// {
335-
// ...options,
336-
// jsonData: { ...options.jsonData, prometheusVersion: undefined },
337-
// },
338-
// (options) => {
339-
// // Check buildinfo api and set default version if we can
340-
// setPrometheusVersion(options, onOptionsChange, onUpdate);
341-
// return onOptionsChange({
342-
// ...options,
343-
// jsonData: { ...options.jsonData, prometheusVersion: undefined },
344-
// });
345-
// }
346-
// )}
347234
onChange={onChangeHandler('prometheusType', options, onOptionsChange)}
348235
width={40}
349236
/>

0 commit comments

Comments
 (0)