mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Google Cloud Monitor: send ServerTiming and metricDescriptors (#67873)
* CloudMonitor: send ServerTiming and metricDescriptors * fix lint
This commit is contained in:
@@ -10,7 +10,9 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/andybalholm/brotli"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/resource/httpadapter"
|
||||
@@ -304,7 +306,11 @@ func doRequest(req *http.Request, cli *http.Client, responseFn processResponse)
|
||||
}
|
||||
|
||||
func getResponses(req *http.Request, cli *http.Client, responseFn processResponse) ([]json.RawMessage, http.Header, string, int, error) {
|
||||
timings := ""
|
||||
start := time.Now()
|
||||
result := doRequest(req, cli, responseFn)
|
||||
elapsed := time.Since(start)
|
||||
timings = timings + " " + strconv.FormatFloat(elapsed.Seconds(), 'f', 10, 64)
|
||||
if result.err != nil {
|
||||
return nil, nil, "", result.code, result.err
|
||||
}
|
||||
@@ -312,17 +318,21 @@ func getResponses(req *http.Request, cli *http.Client, responseFn processRespons
|
||||
token := result.token
|
||||
responses := result.responses
|
||||
for token != "" {
|
||||
start = time.Now()
|
||||
query := req.URL.Query()
|
||||
query.Set("pageToken", token)
|
||||
req.URL.RawQuery = query.Encode()
|
||||
|
||||
loopResult := doRequest(req, cli, responseFn)
|
||||
elapsed = time.Since(start)
|
||||
timings = timings + " " + strconv.FormatFloat(elapsed.Seconds(), 'f', 10, 64)
|
||||
if loopResult.err != nil {
|
||||
return nil, nil, "", loopResult.code, loopResult.err
|
||||
}
|
||||
responses = append(responses, loopResult.responses...)
|
||||
token = loopResult.token
|
||||
}
|
||||
result.header.Set("Server-Timing", fmt.Sprintf("doRequest;dur=%v", timings))
|
||||
return responses, result.header, result.encoding, result.code, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import React, { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
import { GrafanaTheme2, SelectableValue, TimeRange } from '@grafana/data';
|
||||
import { EditorField, EditorFieldGroup, EditorRow } from '@grafana/experimental';
|
||||
import { reportInteraction } from '@grafana/runtime';
|
||||
import { getSelectStyles, Select, AsyncSelect, useStyles2, useTheme2 } from '@grafana/ui';
|
||||
|
||||
import CloudMonitoringDatasource from '../datasource';
|
||||
@@ -88,6 +89,9 @@ export function Editor({
|
||||
const loadMetricDescriptors = async () => {
|
||||
if (projectName) {
|
||||
const metricDescriptors = await datasource.getMetricTypes(projectName);
|
||||
reportInteraction('cloud-monitoring-metric-descriptors-loaded', {
|
||||
count: metricDescriptors.length,
|
||||
});
|
||||
const services = getServicesList(metricDescriptors);
|
||||
setMetricDescriptors(metricDescriptors);
|
||||
setServices(services);
|
||||
|
||||
Reference in New Issue
Block a user