Skip to content

Commit 40a39cc

Browse files
authored
Merge branch 'main' into ddelnano/upgrade-grafana-plugin-sdk
Signed-off-by: Dom Delnano <[email protected]>
2 parents 6194b11 + 2c00838 commit 40a39cc

File tree

7 files changed

+46
-99
lines changed

7 files changed

+46
-99
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ jobs:
2323
# Make sure to save the token in your repository secrets
2424
#policy_token: $
2525
# Usage of GRAFANA_API_KEY is deprecated, prefer `policy_token` option above
26-
#grafana_token: $
26+
#grafana_token: $

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.0.10
4+
5+
- Enable alerting for Pixie datasource
6+
- Fix bug where plugin settings didn't show the present value for cloud address (Fixes [grafana-plugin#100](https://github.com/pixie-io/grafana-plugin/issues/100)
7+
38
## 0.0.9
49

510
- Update Grafana compatibility version

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pixie-pixie-datasource",
3-
"version": "0.0.9",
3+
"version": "0.0.10",
44
"description": "Pixie's Grafana Datasource Plugin",
55
"scripts": {
66
"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",

pkg/pixie_plugin.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,17 @@ func (td *PixieDatasource) QueryData(ctx context.Context, req *backend.QueryData
5959
// Loop over queries and execute them individually. Save the response
6060
// in a hashmap with RefID as identifier.
6161
for _, q := range req.Queries {
62-
res, err := td.query(ctx, q, req.PluginContext.DataSourceInstanceSettings.DecryptedSecureJSONData)
62+
dataSourceSettings := req.PluginContext.DataSourceInstanceSettings
63+
jsonData := dataSourceSettings.JSONData
64+
secureJsonData := dataSourceSettings.DecryptedSecureJSONData
65+
66+
var jsonDataMap map[string]interface{}
67+
err := json.Unmarshal(jsonData, &jsonDataMap)
68+
if err != nil {
69+
return nil, fmt.Errorf("error unmarshalling JSON: %v", err)
70+
}
71+
72+
res, err := td.query(ctx, q, jsonDataMap, secureJsonData)
6373
if err != nil {
6474
return response, err
6575
}
@@ -149,11 +159,12 @@ type queryModel struct {
149159

150160
// Handle an incoming query
151161
func (td *PixieDatasource) query(ctx context.Context, query backend.DataQuery,
152-
config map[string]string) (*backend.DataResponse, error) {
162+
config map[string]interface{}, decryptedConfig map[string]string) (*backend.DataResponse, error) {
163+
164+
cloudAddr := config[cloudAddrField].(string)
153165

154-
apiToken := config[apiKeyField]
155-
cloudAddr := config[cloudAddrField]
156-
clusterID := config[clusterIDField]
166+
apiToken := decryptedConfig[apiKeyField]
167+
clusterID := decryptedConfig[clusterIDField]
157168
var qm queryModel
158169
if err := json.Unmarshal(query.JSON, &qm); err != nil {
159170
return nil, fmt.Errorf("error unmarshalling JSON: %v", err)

src/config_editor.tsx

Lines changed: 16 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
*/
1818

19-
import React, { ChangeEvent, PureComponent } from 'react';
19+
import React, { PureComponent } from 'react';
2020
import { LegacyForms } from '@grafana/ui';
21-
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
21+
import {
22+
DataSourcePluginOptionsEditorProps,
23+
onUpdateDatasourceJsonDataOption,
24+
onUpdateDatasourceSecureJsonDataOption,
25+
updateDatasourcePluginResetOption,
26+
} from '@grafana/data';
2227
import { PixieDataSourceOptions, PixieSecureDataSourceOptions } from './types';
2328

2429
const { FormField, SecretFormField } = LegacyForms;
@@ -28,94 +33,19 @@ interface Props extends DataSourcePluginOptionsEditorProps<PixieDataSourceOption
2833
interface State {}
2934

3035
export class ConfigEditor extends PureComponent<Props, State> {
31-
onAPIKeyChange = (event: ChangeEvent<HTMLInputElement>) => {
32-
const { onOptionsChange, options } = this.props;
33-
34-
onOptionsChange({
35-
...options,
36-
secureJsonData: {
37-
...options?.secureJsonData,
38-
apiKey: event.target.value,
39-
},
40-
});
41-
};
42-
43-
onClusterIdChange = (event: ChangeEvent<HTMLInputElement>) => {
44-
const { onOptionsChange, options } = this.props;
45-
46-
onOptionsChange({
47-
...options,
48-
secureJsonData: {
49-
...options?.secureJsonData,
50-
clusterId: event.target.value,
51-
},
52-
});
53-
};
54-
55-
onCloudAddrChange = (event: ChangeEvent<HTMLInputElement>) => {
56-
const { onOptionsChange, options } = this.props;
57-
58-
onOptionsChange({
59-
...options,
60-
secureJsonData: {
61-
...options?.secureJsonData,
62-
cloudAddr: event.target.value,
63-
},
64-
});
65-
};
66-
6736
onResetAPIKey = () => {
68-
const { onOptionsChange, options } = this.props;
69-
70-
onOptionsChange({
71-
...options,
72-
secureJsonFields: {
73-
...options.secureJsonFields,
74-
apiKey: false,
75-
},
76-
secureJsonData: {
77-
...options.secureJsonData,
78-
apiKey: '',
79-
},
80-
});
37+
updateDatasourcePluginResetOption(this.props, 'apiKey');
8138
};
8239

8340
onResetClusterId = () => {
84-
const { onOptionsChange, options } = this.props;
85-
86-
onOptionsChange({
87-
...options,
88-
secureJsonFields: {
89-
...options.secureJsonFields,
90-
clusterId: false,
91-
},
92-
secureJsonData: {
93-
...options.secureJsonData,
94-
clusterId: '',
95-
},
96-
});
97-
};
98-
99-
onResetCloudAddr = () => {
100-
const { onOptionsChange, options } = this.props;
101-
102-
onOptionsChange({
103-
...options,
104-
secureJsonFields: {
105-
...options.secureJsonFields,
106-
cloudAddr: false,
107-
},
108-
secureJsonData: {
109-
...options.secureJsonData,
110-
cloudAddr: '',
111-
},
112-
});
41+
updateDatasourcePluginResetOption(this.props, 'clusterId');
11342
};
11443

11544
render() {
11645
const { options } = this.props;
11746
const { secureJsonFields } = options;
11847
const secureJsonData = (options.secureJsonData || {}) as PixieSecureDataSourceOptions;
48+
const jsonData = (options.jsonData || {}) as PixieDataSourceOptions;
11949

12050
return (
12151
<div className="gf-form-group">
@@ -129,7 +59,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
12959
labelWidth={20}
13060
inputWidth={20}
13161
onReset={this.onResetAPIKey}
132-
onChange={this.onAPIKeyChange}
62+
onChange={onUpdateDatasourceSecureJsonDataOption(this.props, 'apiKey')}
13363
/>
13464
</div>
13565
</div>
@@ -144,21 +74,20 @@ export class ConfigEditor extends PureComponent<Props, State> {
14474
labelWidth={20}
14575
inputWidth={20}
14676
onReset={this.onResetClusterId}
147-
onChange={this.onClusterIdChange}
77+
onChange={onUpdateDatasourceSecureJsonDataOption(this.props, 'clusterId')}
14878
/>
14979
</div>
15080
</div>
15181

15282
<div className="gf-form-inline">
15383
<div className="gf-form">
15484
<FormField
155-
value={secureJsonData.cloudAddr || ''}
156-
label="Pixie Cloud address (if not using withpixie.ai)"
157-
placeholder="withpixie.ai:443"
85+
value={jsonData.cloudAddr || ''}
86+
label="Pixie Cloud address (if not using getcosmic.ai)"
87+
placeholder="getcosmic.ai:443"
15888
labelWidth={20}
15989
inputWidth={20}
160-
onReset={this.onResetCloudAddr}
161-
onChange={this.onCloudAddrChange}
90+
onChange={onUpdateDatasourceJsonDataOption(this.props, 'cloudAddr')}
16291
/>
16392
</div>
16493
</div>

src/plugin.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"id": "pixie-pixie-datasource",
66
"metrics": true,
77
"backend": true,
8+
"alerting": true,
89
"executable": "gpx-pixie-pixie-datasource-plugin",
910
"info": {
1011
"description": "Pixie's Grafana Datasource Plugin",
@@ -85,8 +86,8 @@
8586
"path": "img/screenshots/namespace-metrics-script.png"
8687
}
8788
],
88-
"version": "0.0.9",
89-
"updated": "2022-08-26"
89+
"version": "0.0.10",
90+
"updated": "2024-11-05"
9091
},
9192
"dependencies": {
9293
"grafanaDependency": ">=7.3.0",

src/types.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ export const defaultQuery: Partial<PixieDataQuery> = {
6969
},
7070
};
7171

72-
export interface PixieDataSourceOptions extends DataSourceJsonData {}
72+
export interface PixieDataSourceOptions extends DataSourceJsonData {
73+
// Address of Pixie cloud.
74+
cloudAddr?: string;
75+
}
7376

7477
export interface PixieSecureDataSourceOptions {
7578
// Pixie API key.
7679
apiKey?: string;
77-
// Address of Pixie cloud.
78-
cloudAddr?: string;
7980
// ID of the Pixie cluster to query.
8081
clusterId?: string;
8182
}

0 commit comments

Comments
 (0)