Skip to content

Commit 9f1cf7e

Browse files
authored
Upgrade to Grafana 8.3.0 (#93)
* Upgrade to Grafana 8.3.0 * Fix tests * Fix LGTM
1 parent 648dcfb commit 9f1cf7e

File tree

18 files changed

+1773
-1431
lines changed

18 files changed

+1773
-1431
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: Setup Node.js environment
1313
uses: actions/setup-node@v2.1.2
1414
with:
15-
node-version: "14.x"
15+
node-version: "16.x"
1616

1717
- name: Get yarn cache directory path
1818
id: yarn-cache-dir-path

.github/workflows/docker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup Node.js environment
1919
uses: actions/setup-node@v2.1.2
2020
with:
21-
node-version: "14.x"
21+
node-version: "16.x"
2222

2323
- name: Get yarn cache directory path
2424
id: yarn-cache-dir-path

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup Node.js environment
1616
uses: actions/setup-node@v2.1.2
1717
with:
18-
node-version: "14.x"
18+
node-version: "16.x"
1919

2020
- name: Get yarn cache directory path
2121
id: yarn-cache-dir-path

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
### Features / Enhancements
66

77
- Upgrade to Grafana 8.2.5 (#88)
8-
- Add CLUSTER Slots commands introduces in Redis 7
8+
- Add CLUSTER Slots commands introduces in Redis 7 (#89)
9+
- Fix Docker plugins provisioning (#90)
10+
- Upgrade to Grafana 8.3.0
911

1012
## 2.1.0 (2021-11-10)
1113

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"author": "RedisGrafana",
33
"description": "Redis Application for Grafana",
44
"devDependencies": {
5-
"@grafana/data": "8.2.5",
6-
"@grafana/runtime": "8.2.5",
7-
"@grafana/toolkit": "8.2.5",
8-
"@grafana/ui": "8.2.5",
5+
"@grafana/data": "8.3.0",
6+
"@grafana/runtime": "8.3.0",
7+
"@grafana/toolkit": "8.3.0",
8+
"@grafana/ui": "8.3.0",
99
"@monaco-editor/react": "^4.3.1",
1010
"@types/enzyme": "^3.10.10",
1111
"@types/enzyme-adapter-react-16": "^1.0.6",
@@ -15,7 +15,7 @@
1515
"tslib": "^2.3.1"
1616
},
1717
"engines": {
18-
"node": ">=12"
18+
"node": ">=14"
1919
},
2020
"license": "Apache-2.0",
2121
"name": "redis-app",

src/components/root-page/root-page.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import { Observable } from 'rxjs';
44
import { AppPluginMeta, PluginType } from '@grafana/data';
55
import { Alert } from '@grafana/ui';
6-
import { ApplicationName, DataSourceType, RedisCommand } from '../../constants';
6+
import { ApplicationName, ApplicationSubTitle, DataSourceType, RedisCommand } from '../../constants';
77
import { DataSourceList } from '../data-source-list';
88
import { RootPage } from './root-page';
99

@@ -163,7 +163,7 @@ describe('RootPage', () => {
163163
const node = {
164164
text: ApplicationName,
165165
img: meta.info.logos.large,
166-
subTitle: 'Redis Data Source',
166+
subTitle: ApplicationSubTitle,
167167
url: path,
168168
children: [
169169
{

src/components/root-page/root-page.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { PureComponent } from 'react';
2-
import { Observable } from 'rxjs';
2+
import { lastValueFrom, Observable } from 'rxjs';
33
import {
44
AppRootProps,
55
DataQueryRequest,
@@ -10,7 +10,7 @@ import {
1010
} from '@grafana/data';
1111
import { config, getBackendSrv, getDataSourceSrv } from '@grafana/runtime';
1212
import { Alert } from '@grafana/ui';
13-
import { ApplicationName, DataSourceType, RedisCommand } from '../../constants';
13+
import { ApplicationName, ApplicationSubTitle, DataSourceType, RedisCommand } from '../../constants';
1414
import { RedisQuery } from '../../redis-cli-panel/types';
1515
import { GlobalSettings, RedisDataSourceInstanceSettings } from '../../types';
1616
import { DataSourceList } from '../data-source-list';
@@ -107,16 +107,15 @@ export class RootPage extends PureComponent<Props, State> {
107107
targets: [{ refId: 'A', query: RedisCommand.COMMAND }],
108108
} as DataQueryRequest<RedisQuery>) as unknown;
109109

110-
const query = dsQuery as Observable<DataQueryResponse>;
111-
if (!query.toPromise) {
110+
const query = lastValueFrom(dsQuery as Observable<DataQueryResponse>);
111+
if (!query) {
112112
return;
113113
}
114114

115115
/**
116116
* Get available commands
117117
*/
118118
await query
119-
.toPromise()
120119
.then((response: DataQueryResponse) => response.data)
121120
.then((data: DataQueryResponseData[]) =>
122121
data.forEach((item: DataQueryResponseData) => {
@@ -167,7 +166,7 @@ export class RootPage extends PureComponent<Props, State> {
167166
const node = {
168167
text: ApplicationName,
169168
img: meta.info.logos.large,
170-
subTitle: 'Redis Data Source',
169+
subTitle: ApplicationSubTitle,
171170
url: path,
172171
children: tabs,
173172
};

src/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export enum ClientTypeValue {
4242
export const ApplicationRoot = '/a/redis-app';
4343

4444
/**
45-
* Application's name
45+
* Application
4646
*/
4747
export const ApplicationName = 'Redis Application';
48+
export const ApplicationSubTitle = 'Redis Data Source Manager';

src/redis-cli-panel/components/redis-cli-panel/redis-cli-panel.test.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,51 @@ describe('RedisCLIPanel', () => {
493493
done();
494494
});
495495
});
496+
497+
it('Run query with error received', (done) => {
498+
const getDataSourceQueryError = () => ({
499+
error: {
500+
message: 'Error',
501+
},
502+
data: [],
503+
});
504+
505+
dataSourceMock.query.mockImplementationOnce(
506+
() =>
507+
new Observable((subscriber) => {
508+
subscriber.next(getDataSourceQueryError());
509+
subscriber.complete();
510+
})
511+
);
512+
513+
const options = getOptions({
514+
query: 'WRONG COMMAND',
515+
output: '',
516+
});
517+
const overrideData = {
518+
...data,
519+
request: { targets: [{ datasource: 'datasource/id' }] },
520+
};
521+
522+
const wrapper = shallow(
523+
<RedisCLIPanel
524+
{...additionalProps}
525+
width={width}
526+
height={height}
527+
data={overrideData}
528+
onOptionsChange={onOptionsChangeMock}
529+
replaceVariables={replaceVariablesMock}
530+
options={options}
531+
/>
532+
);
533+
534+
const testedComponent = getTestedComponent(wrapper);
535+
testedComponent.simulate('keypress', { key: 'Enter' });
536+
setImmediate(() => {
537+
expect(onOptionsChangeMock).toHaveBeenCalled();
538+
done();
539+
});
540+
});
496541
});
497542

498543
it('Clear button should clean output', () => {

src/redis-cli-panel/components/redis-cli-panel/redis-cli-panel.tsx

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import React, { ChangeEvent } from 'react';
2-
import { Observable } from 'rxjs';
3-
import { map as map$, switchMap as switchMap$ } from 'rxjs/operators';
2+
import { lastValueFrom, Observable } from 'rxjs';
43
import { RedisDataSourceOptions } from 'types';
54
import { css, cx } from '@emotion/css';
6-
import { DataFrame, DataQueryRequest, DataQueryResponse, PanelProps } from '@grafana/data';
5+
import {
6+
DataQueryRequest,
7+
DataQueryResponse,
8+
DataQueryResponseData,
9+
DataSourceRef,
10+
Field,
11+
PanelProps,
12+
} from '@grafana/data';
713
import { getDataSourceSrv } from '@grafana/runtime';
814
import { Button, RadioButtonGroup, useTheme2 } from '@grafana/ui';
915
import { Help, ResponseMode, ResponseModeOptions } from '../../constants';
@@ -29,7 +35,7 @@ export const RedisCLIPanel: React.FC<PanelProps<PanelOptions>> = ({
2935
* Get configured Data Source Id
3036
*/
3137
const targets = data.request?.targets;
32-
let datasource = '';
38+
let datasource: string | DataSourceRef = '';
3339
if (targets && targets.length && targets[0].datasource) {
3440
datasource = targets[0].datasource;
3541
}
@@ -64,33 +70,39 @@ export const RedisCLIPanel: React.FC<PanelProps<PanelOptions>> = ({
6470
const dsQuery = ds.query({
6571
targets: [{ refId: 'A', query: replaceVariables(query), cli: !options.raw }],
6672
} as DataQueryRequest<RedisQuery>) as unknown;
67-
const res = await (dsQuery as Observable<DataQueryResponse>)
68-
.pipe(
69-
switchMap$((response) => {
70-
/**
71-
* Check for error in response
72-
*/
73-
if (response.error && response.error.message) {
74-
error = response.error.message;
75-
}
76-
77-
return response.data;
78-
}),
79-
switchMap$((data: DataFrame) => data.fields),
80-
map$((field) =>
81-
field.values.toArray().map((value) => {
82-
return value;
83-
})
84-
)
85-
)
86-
.toPromise();
73+
const q = lastValueFrom(dsQuery as Observable<DataQueryResponse>);
8774

8875
/**
89-
* Result
76+
* Get Results
77+
*/
78+
const results: string[] = [];
79+
await q
80+
.then((response: DataQueryResponse) => {
81+
/**
82+
* Check for error in response
83+
*/
84+
if (response.error && response.error.message) {
85+
error = response.error.message;
86+
}
87+
88+
return response.data;
89+
})
90+
.then((data: DataQueryResponseData[]) =>
91+
data.forEach((item: DataQueryResponseData) => {
92+
item.fields.forEach((field: Field) => {
93+
field.values.toArray().map((value) => {
94+
results.push(value);
95+
});
96+
});
97+
})
98+
);
99+
100+
/**
101+
* Show Output
90102
*/
91103
let result = `${ds.name}> ${query}\n`;
92-
if (res && res.length) {
93-
result += res.join('\n');
104+
if (results.length) {
105+
result += results.join('\n');
94106
} else if (error) {
95107
result += `(error) ${error}\n`;
96108
} else {

0 commit comments

Comments
 (0)