Skip to content

Commit ce8f0a3

Browse files
authored
Merge pull request #137 from scalyr/dtin-6395
2 parents eeaf0c6 + 9516b16 commit ce8f0a3

File tree

4 files changed

+44
-14
lines changed

4 files changed

+44
-14
lines changed

CHANGELOG.md

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

3+
## 3.1.7
4+
5+
- Plugin setup changes:
6+
- Use a less expensive api key check
7+
- Ensure the default DataSet url is set
8+
39
## 3.1.6
410

511
- Rate limit DataSet LRQ sessions rather than HTTP requests

pkg/plugin/plugin.go

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -275,24 +275,47 @@ func displayPQData(result *LRQResult, response backend.DataResponse) backend.Dat
275275
return response
276276
}
277277

278-
// CheckHealth handles health checks sent from Grafana to the plugin.
279-
// The main use case for these health checks is the test button on the
280-
// datasource configuration page which allows users to verify that
281-
// a datasource is working as expected.
278+
// CheckHealth handles health checks sent from the Grafana server to the plugin.
279+
// Used by the test button on the config page to validate the DataSet url and api key.
282280
func (d *DataSetDatasource) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
283-
statusCode, err := d.dataSetClient.DoFacetRequest(ctx, FacetRequest{
284-
QueryType: "facet",
285-
MaxCount: 1,
286-
Field: "test",
287-
})
281+
const refId = "A"
282+
const powerQuery = "grafana_plugin_checkhealth=1 | limit 1"
283+
284+
resp, err := d.QueryData(
285+
ctx,
286+
&backend.QueryDataRequest{
287+
Queries: []backend.DataQuery{
288+
{
289+
RefID: refId,
290+
TimeRange: backend.TimeRange{
291+
From: time.Now().Add(-1 * time.Minute),
292+
To: time.Now(),
293+
},
294+
JSON: []byte(fmt.Sprintf(`{"expression":"%s","queryType":"Power Query"}`, powerQuery)),
295+
},
296+
},
297+
},
298+
)
288299
if err != nil {
289-
return nil, err
300+
return &backend.CheckHealthResult{
301+
Status: backend.HealthStatusError,
302+
Message: "Failed to connect to DataSet: QueryData failed: " + err.Error(),
303+
}, nil
304+
}
305+
306+
dataResp, ok := resp.Responses[refId]
307+
if !ok {
308+
return &backend.CheckHealthResult{
309+
Status: backend.HealthStatusError,
310+
Message: "Failed to connect to DataSet: No response for RefID " + refId,
311+
}, nil
290312
}
291313

292-
if statusCode != 200 {
314+
// DataResponse.Error is set when the http status code is not 200
315+
if dataResp.Error != nil {
293316
return &backend.CheckHealthResult{
294317
Status: backend.HealthStatusError,
295-
Message: "Failed to connect to DataSet, please inspect the Grafana server log for details",
318+
Message: "Failed to connect to DataSet: DataResponse.Error: " + dataResp.Error.Error(),
296319
}, nil
297320
}
298321

pkg/plugin/plugin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TestLiveQueryDataPlot(t *testing.T) {
130130
},
131131
Interval: 1 * time.Minute,
132132
MaxDataPoints: 1000,
133-
JSON: []byte(`{"expression":"count(severity != 3)","queryType":"Standard","breakDownFacetValue":"severity"}`),
133+
JSON: []byte(`{"expression":"count(serverHost='scalyr-metalog')","queryType":"Standard","breakDownFacetValue":"tag"}`),
134134
},
135135
},
136136
},

src/ConfigEditor.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
4949
render() {
5050
const { options } = this.props;
5151
const { jsonData, secureJsonFields } = options;
52+
jsonData.scalyrUrl = jsonData.scalyrUrl || 'https://app.scalyr.com';
5253
const secureJsonData = (options.secureJsonData || {}) as MySecureJsonData;
5354

5455
return (
@@ -75,7 +76,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
7576
labelWidth={8}
7677
inputWidth={20}
7778
onChange={this.onURLChange}
78-
value={jsonData.scalyrUrl || 'https://app.scalyr.com'}
79+
value={jsonData.scalyrUrl}
7980
placeholder="Scalyr server URL"
8081
/>
8182
</div>

0 commit comments

Comments
 (0)