|
1 | 1 | import {
|
2 | 2 | DataSourcePluginOptionsEditorProps,
|
3 |
| - /* DataSourceSettings as DataSourceSettingsType, */ |
4 | 3 | onUpdateDatasourceJsonDataOptionChecked,
|
5 | 4 | SelectableValue,
|
6 | 5 | updateDatasourcePluginJsonDataOption,
|
7 | 6 | } from '@grafana/data';
|
8 | 7 | import { ConfigSubSection } from '@grafana/experimental';
|
9 |
| -// import { config/*, getBackendSrv */} from '@grafana/runtime'; |
10 | 8 | import { InlineField, Input, Select, Switch, useTheme2 } from '@grafana/ui';
|
11 | 9 | import React, { SyntheticEvent, useState } from 'react';
|
12 |
| -// import semver from 'semver/preload'; |
13 | 10 |
|
14 |
| - |
15 |
| -// import { useUpdateDatasource } from '../../../../features/datasources/state'; |
16 |
| -// import { PromApplication, PromBuildInfoResponse } from '../../../../types/unified-alerting-dto'; |
17 | 11 | import { QueryEditorMode } from '../querybuilder/shared/types';
|
18 | 12 | import { defaultPrometheusQueryOverlapWindow } from '../querycache/QueryCache';
|
19 |
| -import { PromApplication, /*PromBuildInfoResponse,*/ PrometheusCacheLevel, PromOptions } from '../types'; |
| 13 | +import { PromApplication, PrometheusCacheLevel, PromOptions } from '../types'; |
20 | 14 |
|
21 | 15 | import { docsTip, overhaulStyles, PROM_CONFIG_LABEL_WIDTH, validateInput } from './ConfigEditor';
|
22 | 16 | import { ExemplarsSettings } from './ExemplarsSettings';
|
@@ -57,108 +51,17 @@ export const DURATION_REGEX = /^$|^\d+(ms|[Mwdhmsy])$/;
|
57 | 51 | export const MULTIPLE_DURATION_REGEX = /(\d+)(.+)/;
|
58 | 52 |
|
59 | 53 | 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 |
| -// }; |
145 | 54 |
|
146 | 55 | export const PromSettings = (props: Props) => {
|
147 | 56 | const { options, onOptionsChange } = props;
|
148 | 57 |
|
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 |
| - |
153 | 58 | // We are explicitly adding httpMethod so, it is correctly displayed in dropdown.
|
154 | 59 | // This way, it is more predictable for users.
|
155 | 60 | if (!options.jsonData.httpMethod) {
|
156 | 61 | options.jsonData.httpMethod = 'POST';
|
157 | 62 | }
|
158 | 63 |
|
159 | 64 | const theme = useTheme2();
|
160 |
| - // imported GrafanaTheme2 from @grafana/data does not match type of same from @grafana/ui |
161 |
| - // @ts-ignore |
162 | 65 | const styles = overhaulStyles(theme);
|
163 | 66 |
|
164 | 67 | type ValidDuration = {
|
@@ -328,22 +231,6 @@ export const PromSettings = (props: Props) => {
|
328 | 231 | aria-label="Prometheus type"
|
329 | 232 | options={prometheusFlavorSelectItems}
|
330 | 233 | 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 |
| - // )} |
347 | 234 | onChange={onChangeHandler('prometheusType', options, onOptionsChange)}
|
348 | 235 | width={40}
|
349 | 236 | />
|
|
0 commit comments