Skip to content

Commit 22451bf

Browse files
committed
Remove WebAPI support
1 parent 2d2d181 commit 22451bf

25 files changed

+137
-589
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
run: npm ci --prefer-offline
4747

4848
- name: Run prettier
49-
run: npm run pretty:check
49+
run: npm run pretty
5050

5151
- name: Check types
5252
run: npm run typecheck

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
dist/
2+
src/plugin.json

DEVELOPMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ https://grafana.com/developers/plugin-tools/migration-guides/update-create-plugi
3939
npx @grafana/create-plugin@latest update
4040
npm install
4141
npx npm-check-updates -i --format group
42-
npm run pretty
42+
npm run pretty:fix
4343
```
4444

4545
## Release

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ To make use of the plugin, you need to take care the correct versions are instal
1818

1919
- **Grafana 9.5.15 or higher** Current and previous major version of Grafana
2020
- **Checkmk Cloud or Checkmk MSP 2.2.0 or higher** for the signed plugin available from [Grafana][6]
21-
- **Checkmk 2.1.0 or higher** for the unsigned plugin available from [Github][8]
21+
- **Checkmk 2.2.0 or higher** for the unsigned plugin available from [Github][8]
2222

2323
## Installing the plug-in
2424

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"typecheck": "tsc --noEmit",
1212
"lint": "eslint --cache --ignore-path ./.gitignore --ext .js,.jsx,.ts,.tsx .",
1313
"lint:fix": "npm run lint --fix",
14-
"pretty": "prettier -w '{**/*,*}.{js,ts,jsx,tsx,json,yml}'",
15-
"pretty:check": "prettier -c '{**/*,*}.{js,ts,jsx,tsx,json,yml}'",
14+
"pretty": "prettier -c '{**/*,*}.{js,ts,jsx,tsx,json,yml}'",
15+
"pretty:fix": "prettier -w '{**/*,*}.{js,ts,jsx,tsx,json,yml}'",
1616
"server": "docker-compose up --build",
1717
"start": "npm run watch",
1818
"sign": "npx --yes @grafana/sign-plugin@latest",

playwright.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ export default defineConfig<PluginOptions>({
1111
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
1212
reporter: 'list',
1313
use: {
14-
trace: 'on',
15-
video: 'on',
14+
trace: 'retain-on-failure',
15+
video: 'retain-on-failure',
16+
screenshot: 'only-on-failure',
1617
viewport: { width: 1920, height: 1080 },
1718
},
1819
projects: [

src/DataSource.ts

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,61 +11,40 @@ import { replaceVariables } from 'utils';
1111

1212
import { MetricFindQuery, RequestSpec } from './RequestSpec';
1313
import RestApiBackend from './backend/rest';
14-
import { BACKEND_TYPE, Backend } from './backend/types';
15-
import WebApiBackend from './backend/web';
1614
import { Settings } from './settings';
17-
import { Backend as BackendType, CmkQuery, DataSourceOptions, Edition, ResponseDataAutocomplete } from './types';
15+
import { CmkQuery, DataSourceOptions, Edition, ResponseDataAutocomplete, type WebApiResponse } from './types';
1816
import { AutoCompleteParams } from './ui/autocomplete';
1917
import { createCmkContext } from './utils';
20-
import { WebApiResponse } from './webapi';
2118

2219
export class DataSource extends DataSourceApi<CmkQuery> {
23-
webBackend: WebApiBackend;
2420
restBackend: RestApiBackend;
2521
settings: Settings;
26-
autocompleteBackend: BACKEND_TYPE | null = null;
2722

2823
constructor(private instanceSettings: DataSourceInstanceSettings<DataSourceOptions>) {
2924
super(instanceSettings);
30-
this.webBackend = new WebApiBackend(this);
3125
this.restBackend = new RestApiBackend(this);
3226
this.settings = new Settings(instanceSettings.jsonData);
3327
}
3428

35-
protected async setAutocompleteBackend() {
36-
this.autocompleteBackend = await this.getBackend().getAutocompleteBackend();
37-
}
38-
3929
async query(dataQueryRequest: DataQueryRequest<CmkQuery>): Promise<DataQueryResponse> {
4030
for (const target of dataQueryRequest.targets) {
4131
target.requestSpec = replaceVariables(target.requestSpec, dataQueryRequest.scopedVars);
4232
}
43-
return this.getBackend().query(dataQueryRequest);
33+
return this.restBackend.query(dataQueryRequest);
4434
}
4535

4636
async metricFindQuery(query: MetricFindQuery, options?: unknown): Promise<MetricFindValue[]> {
47-
if (query.objectType === 'site') {
48-
// rest-api site endpoint were added in 2.2.0 so we have to use the web-api here
49-
// TODO: clean up (remove filterSites from Backend) with end of 2.1.0
50-
return await this.getBackend().listSites();
51-
}
52-
// we use the rest backend for both web and rest backend, because those endpoints are already implement in 2.1.0
5337
return await this.restBackend.metricFindQuery(query);
5438
}
39+
5540
async testDatasource(): Promise<TestDataSourceResponse> {
56-
return this.getBackend().testDatasource();
41+
return this.restBackend.testDatasource();
5742
}
5843

5944
async autocompleterRequest(
6045
api_url: string,
6146
data: unknown
6247
): Promise<FetchResponse<WebApiResponse<ResponseDataAutocomplete>>> {
63-
this.autocompleteBackend === null && (await this.setAutocompleteBackend());
64-
65-
if (this.autocompleteBackend === BACKEND_TYPE.WEB) {
66-
return this.webBackend.autocompleterRequest(api_url, data);
67-
}
68-
6948
return this.restBackend.autocompleterRequest(api_url, data);
7049
}
7150

@@ -75,26 +54,8 @@ export class DataSource extends DataSourceApi<CmkQuery> {
7554
prefix: string,
7655
params: Partial<AutoCompleteParams>
7756
): Promise<Array<{ value: string; label: string; isDisabled: boolean }>> {
78-
if (ident === 'label' && this.getBackendType() === 'web') {
79-
// we have a 2.1.0 version without werk #15074 so label autocompleter is a special edge case
80-
// can be removed after we stop supporting 2.1.0
81-
const response = await this.webBackend.autocompleterRequest<Array<{ value: string }>>(
82-
'ajax_autocomplete_labels.py',
83-
{
84-
world: params.world,
85-
search_label: prefix,
86-
}
87-
);
88-
return response.data.result.map((val: { value: string }) => ({
89-
value: val.value,
90-
label: val.value,
91-
isDisabled: false,
92-
}));
93-
}
94-
const context = createCmkContext(
95-
replaceVariables(partialRequestSpec),
96-
this.getBackendType() === 'rest' ? 'latest' : '2.1.0'
97-
);
57+
const context = createCmkContext(replaceVariables(partialRequestSpec));
58+
9859
const response = await this.autocompleterRequest('ajax_vs_autocomplete.py', {
9960
ident,
10061
value: prefix,
@@ -118,17 +79,6 @@ export class DataSource extends DataSourceApi<CmkQuery> {
11879
return this.settings.edition;
11980
}
12081

121-
getBackendType(): BackendType {
122-
return this.settings.backend;
123-
}
124-
125-
getBackend(): Backend {
126-
if (this.getBackendType() === 'web') {
127-
return this.webBackend as Backend;
128-
}
129-
return this.restBackend as Backend;
130-
}
131-
13282
getUsername(): string {
13383
return this.settings.username;
13484
}
File renamed without changes.

src/backend/rest.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import { lastValueFrom } from 'rxjs';
1919
import { Aggregation, GraphType, MetricFindQuery } from '../RequestSpec';
2020
import { CmkQuery, ResponseDataAutocomplete } from '../types';
2121
import { createCmkContext, replaceVariables, toLiveStatusQuery, updateMetricTitles, updateQuery } from '../utils';
22-
import { WebApiResponse } from './../webapi';
23-
import { BACKEND_TYPE, Backend, DatasourceOptions } from './types';
22+
import { type WebApiResponse } from './../types';
23+
import { Backend, DatasourceOptions } from './types';
2424
import { validateRequestSpec } from './validate';
2525

2626
type RestApiError = {
@@ -179,15 +179,8 @@ export default class RestApiBackend implements Backend {
179179
method: 'GET',
180180
});
181181
const checkMkVersion: string = result.data.versions.checkmk;
182-
if (checkMkVersion.startsWith('2.0') || checkMkVersion.startsWith('1.')) {
183-
throw new Error(
184-
`A Checkmk version below 2.1.0 is not supported for this plugin, but you can set the backend to the '< 2.2' version and use at your own risk.`
185-
);
186-
}
187-
if (checkMkVersion.startsWith('2.1')) {
188-
throw new Error(
189-
`Checkmk version 2.1.0 has been detected, but this plugin is configured to use version 2.2.0 and above. Please set the backend option to '< 2.2'.`
190-
);
182+
if (checkMkVersion.startsWith('2.0') || checkMkVersion.startsWith('2.1') || checkMkVersion.startsWith('1.')) {
183+
throw new Error(`A Checkmk version below 2.2.0 is not supported for this plugin.`);
191184
}
192185
if (this.datasource.getEdition() !== 'RAW' && result.data.edition === 'cre') {
193186
throw new Error(
@@ -380,20 +373,6 @@ export default class RestApiBackend implements Backend {
380373
}
381374
}
382375

383-
async getAutocompleteBackend(): Promise<BACKEND_TYPE> {
384-
return this.api<RestApiAutocompleteResponse>({
385-
url: `/objects/autocomplete/sites`,
386-
method: 'POST',
387-
data: { value: '', parameters: {} },
388-
})
389-
.then(() => {
390-
return BACKEND_TYPE.REST;
391-
})
392-
.catch(() => {
393-
return BACKEND_TYPE.WEB;
394-
});
395-
}
396-
397376
async autocompleterRequest(
398377
api_url = '',
399378
data: unknown

src/backend/types.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,14 @@ import { DataQueryRequest, DataQueryResponse, MetricFindValue, TestDataSourceRes
33
import { MetricFindQuery } from '../RequestSpec';
44
import { CmkQuery, Edition } from '../types';
55

6-
export enum BACKEND_TYPE {
7-
REST = 'rest',
8-
WEB = 'web',
9-
}
10-
116
export interface Backend {
127
query: (options: DataQueryRequest<CmkQuery>) => Promise<DataQueryResponse>;
138
testDatasource: () => Promise<TestDataSourceResponse>;
149
metricFindQuery: (query: MetricFindQuery) => Promise<MetricFindValue[]>;
1510
listSites: () => Promise<MetricFindValue[]>;
16-
getAutocompleteBackend: () => Promise<BACKEND_TYPE>;
1711
}
1812

1913
export interface DatasourceOptions {
20-
getBackend: () => Backend;
2114
getEdition: () => Edition;
2215
getUrl: () => string | undefined;
2316
getUsername(): string;

0 commit comments

Comments
 (0)