Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 3.1.7

- Plugin setup changes:
- Use a less expensive api key check
- Ensure the default DataSet url is set

## 3.1.6

- Rate limit DataSet LRQ sessions rather than HTTP requests
Expand Down
47 changes: 35 additions & 12 deletions pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,24 +275,47 @@ func displayPQData(result *LRQResult, response backend.DataResponse) backend.Dat
return response
}

// CheckHealth handles health checks sent from Grafana to the plugin.
// The main use case for these health checks is the test button on the
// datasource configuration page which allows users to verify that
// a datasource is working as expected.
// CheckHealth handles health checks sent from the Grafana server to the plugin.
// Used by the test button on the config page to validate the DataSet url and api key.
func (d *DataSetDatasource) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
statusCode, err := d.dataSetClient.DoFacetRequest(ctx, FacetRequest{
QueryType: "facet",
MaxCount: 1,
Field: "test",
})
const refId = "A"
const powerQuery = "grafana_plugin_checkhealth=1 | limit 1"

resp, err := d.QueryData(
ctx,
&backend.QueryDataRequest{
Queries: []backend.DataQuery{
{
RefID: refId,
TimeRange: backend.TimeRange{
From: time.Now().Add(-1 * time.Minute),
To: time.Now(),
},
JSON: []byte(fmt.Sprintf(`{"expression":"%s","queryType":"Power Query"}`, powerQuery)),
},
},
},
)
if err != nil {
return nil, err
return &backend.CheckHealthResult{
Status: backend.HealthStatusError,
Message: "Failed to connect to DataSet: QueryData failed: " + err.Error(),
}, nil
}

dataResp, ok := resp.Responses[refId]
if !ok {
return &backend.CheckHealthResult{
Status: backend.HealthStatusError,
Message: "Failed to connect to DataSet: No response for RefID " + refId,
}, nil
}

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

Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestLiveQueryDataPlot(t *testing.T) {
},
Interval: 1 * time.Minute,
MaxDataPoints: 1000,
JSON: []byte(`{"expression":"count(severity != 3)","queryType":"Standard","breakDownFacetValue":"severity"}`),
JSON: []byte(`{"expression":"count(serverHost='scalyr-metalog')","queryType":"Standard","breakDownFacetValue":"tag"}`),
},
},
},
Expand Down
3 changes: 2 additions & 1 deletion src/ConfigEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
render() {
const { options } = this.props;
const { jsonData, secureJsonFields } = options;
jsonData.scalyrUrl = jsonData.scalyrUrl || 'https://app.scalyr.com';
const secureJsonData = (options.secureJsonData || {}) as MySecureJsonData;

return (
Expand All @@ -75,7 +76,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
labelWidth={8}
inputWidth={20}
onChange={this.onURLChange}
value={jsonData.scalyrUrl || 'https://app.scalyr.com'}
value={jsonData.scalyrUrl}
placeholder="Scalyr server URL"
/>
</div>
Expand Down
Loading