mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 03:34:15 -06:00
Azure Monitor: Fix empty/errored responses for Logs variables (#59240)
This commit is contained in:
parent
cff36ea7d8
commit
276b54fe9d
@ -190,7 +190,10 @@ func (e *AzureLogAnalyticsDatasource) executeQuery(ctx context.Context, logger l
|
||||
if err != nil {
|
||||
return dataResponseErrorWithExecuted(err)
|
||||
}
|
||||
appendErrorNotice(frame, logResponse.Error)
|
||||
frame = appendErrorNotice(frame, logResponse.Error)
|
||||
if frame == nil {
|
||||
return dataResponse
|
||||
}
|
||||
|
||||
model, err := simplejson.NewJson(query.JSON)
|
||||
if err != nil {
|
||||
@ -222,10 +225,15 @@ func (e *AzureLogAnalyticsDatasource) executeQuery(ctx context.Context, logger l
|
||||
return dataResponse
|
||||
}
|
||||
|
||||
func appendErrorNotice(frame *data.Frame, err *AzureLogAnalyticsAPIError) {
|
||||
if err != nil {
|
||||
frame.AppendNotices(apiErrorToNotice(err))
|
||||
func appendErrorNotice(frame *data.Frame, err *AzureLogAnalyticsAPIError) *data.Frame {
|
||||
if err == nil {
|
||||
return frame
|
||||
}
|
||||
if frame == nil {
|
||||
frame = &data.Frame{}
|
||||
}
|
||||
frame.AppendNotices(apiErrorToNotice(err))
|
||||
return frame
|
||||
}
|
||||
|
||||
func (e *AzureLogAnalyticsDatasource) createRequest(ctx context.Context, logger log.Logger, url string) (*http.Request, error) {
|
||||
|
@ -45,12 +45,7 @@ func apiErrorToNotice(err *AzureLogAnalyticsAPIError) data.Notice {
|
||||
// ResponseTableToFrame converts an AzureResponseTable to a data.Frame.
|
||||
func ResponseTableToFrame(table *types.AzureResponseTable, refID string, executedQuery string) (*data.Frame, error) {
|
||||
if len(table.Rows) == 0 {
|
||||
return &data.Frame{
|
||||
RefID: refID,
|
||||
Meta: &data.FrameMeta{
|
||||
ExecutedQueryString: executedQuery,
|
||||
},
|
||||
}, nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
converterFrame, err := converterFrameForTable(table)
|
||||
|
@ -173,12 +173,7 @@ func TestLogTableToFrame(t *testing.T) {
|
||||
name: "empty data response",
|
||||
testFile: "loganalytics/11-log-analytics-response-empty.json",
|
||||
expectedFrame: func() *data.Frame {
|
||||
return &data.Frame{
|
||||
RefID: "A",
|
||||
Meta: &data.FrameMeta{
|
||||
ExecutedQueryString: "query",
|
||||
},
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -489,6 +489,38 @@ describe('VariableSupport', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('passes on the query error for a log query', (done) => {
|
||||
const variableSupport = new VariableSupport(
|
||||
createMockDatasource({
|
||||
query: () =>
|
||||
from(
|
||||
Promise.resolve({
|
||||
data: [],
|
||||
error: {
|
||||
message: 'boom',
|
||||
},
|
||||
})
|
||||
),
|
||||
})
|
||||
);
|
||||
const mockRequest = {
|
||||
targets: [
|
||||
{
|
||||
queryType: AzureQueryType.LogAnalytics,
|
||||
azureLogAnalytics: {
|
||||
query: 'some log thing',
|
||||
},
|
||||
} as AzureMonitorQuery,
|
||||
],
|
||||
} as DataQueryRequest<AzureMonitorQuery>;
|
||||
const observables = variableSupport.query(mockRequest);
|
||||
observables.subscribe((result: DataQueryResponseData) => {
|
||||
expect(result.data).toEqual([]);
|
||||
expect(result.error.message).toEqual('boom');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle http error', (done) => {
|
||||
const error = invalidSubscriptionError();
|
||||
const variableSupport = new VariableSupport(
|
||||
|
@ -94,6 +94,7 @@ export class VariableSupport extends CustomVariableSupport<DataSource, AzureMoni
|
||||
const queryResp = await lastValueFrom(this.datasource.query(request));
|
||||
return {
|
||||
data: queryResp.data,
|
||||
error: queryResp.error ? new Error(messageFromError(queryResp.error)) : undefined,
|
||||
};
|
||||
}
|
||||
} catch (err) {
|
||||
|
Loading…
Reference in New Issue
Block a user