CloudMonitoring: Use response unit instead of metric descriptor unit (#32928)
* improve unit detection * Update docs/sources/datasources/google-cloud-monitoring/_index.md Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * goimports * fix typo * golint fixes * Update docs/sources/datasources/google-cloud-monitoring/_index.md Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update docs/sources/datasources/google-cloud-monitoring/_index.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/datasources/google-cloud-monitoring/_index.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/datasources/google-cloud-monitoring/_index.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/datasources/google-cloud-monitoring/_index.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * pr feedback * Update docs/sources/datasources/google-cloud-monitoring/_index.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>
This commit is contained in:
co-authored by
Ursula Kallio
Diana Payton
achatterjee-grafana
parent
9f82eac833
commit
dac9393061
@@ -48,6 +48,7 @@ var (
|
||||
"us": "µs",
|
||||
"ms": "ms",
|
||||
"ns": "ns",
|
||||
"%": "percent",
|
||||
"percent": "percent",
|
||||
"MiBy": "mbytes",
|
||||
"By/s": "Bps",
|
||||
@@ -157,8 +158,6 @@ func (e *Executor) executeTimeSeriesQuery(ctx context.Context, tsdbQuery plugins
|
||||
return plugins.DataResponse{}, err
|
||||
}
|
||||
|
||||
unit := e.resolvePanelUnitFromQueries(queryExecutors)
|
||||
|
||||
for _, queryExecutor := range queryExecutors {
|
||||
queryRes, resp, executedQueryString, err := queryExecutor.run(ctx, tsdbQuery, e)
|
||||
if err != nil {
|
||||
@@ -170,43 +169,11 @@ func (e *Executor) executeTimeSeriesQuery(ctx context.Context, tsdbQuery plugins
|
||||
}
|
||||
|
||||
result.Results[queryExecutor.getRefID()] = queryRes
|
||||
|
||||
if len(unit) > 0 {
|
||||
frames, _ := queryRes.Dataframes.Decoded()
|
||||
for i := range frames {
|
||||
if frames[i].Fields[1].Config == nil {
|
||||
frames[i].Fields[1].Config = &data.FieldConfig{}
|
||||
}
|
||||
frames[i].Fields[1].Config.Unit = unit
|
||||
}
|
||||
queryRes.Dataframes = plugins.NewDecodedDataFrames(frames)
|
||||
}
|
||||
result.Results[queryExecutor.getRefID()] = queryRes
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (e *Executor) resolvePanelUnitFromQueries(executors []cloudMonitoringQueryExecutor) string {
|
||||
if len(executors) == 0 {
|
||||
return ""
|
||||
}
|
||||
unit := executors[0].getUnit()
|
||||
if len(executors) > 1 {
|
||||
for _, query := range executors[1:] {
|
||||
if query.getUnit() != unit {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(unit) > 0 {
|
||||
if val, ok := cloudMonitoringUnitMappings[unit]; ok {
|
||||
return val
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (e *Executor) buildQueryExecutors(tsdbQuery plugins.DataQuery) ([]cloudMonitoringQueryExecutor, error) {
|
||||
cloudMonitoringQueryExecutors := []cloudMonitoringQueryExecutor{}
|
||||
|
||||
@@ -282,7 +249,6 @@ func (e *Executor) buildQueryExecutors(tsdbQuery plugins.DataQuery) ([]cloudMoni
|
||||
target = params.Encode()
|
||||
cmtsf.Target = target
|
||||
cmtsf.Params = params
|
||||
cmtsf.Unit = q.MetricQuery.Unit
|
||||
|
||||
if setting.Env == setting.Dev {
|
||||
slog.Debug("CloudMonitoring request", "params", params)
|
||||
@@ -601,7 +567,7 @@ func unmarshalResponse(res *http.Response) (cloudMonitoringResponse, error) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func addConfigData(frames data.Frames, dl string) data.Frames {
|
||||
func addConfigData(frames data.Frames, dl string, unit string) data.Frames {
|
||||
for i := range frames {
|
||||
if frames[i].Fields[1].Config == nil {
|
||||
frames[i].Fields[1].Config = &data.FieldConfig{}
|
||||
@@ -612,6 +578,11 @@ func addConfigData(frames data.Frames, dl string) data.Frames {
|
||||
URL: dl,
|
||||
}
|
||||
frames[i].Fields[1].Config.Links = append(frames[i].Fields[1].Config.Links, deepLink)
|
||||
if len(unit) > 0 {
|
||||
if val, ok := cloudMonitoringUnitMappings[unit]; ok {
|
||||
frames[i].Fields[1].Config.Unit = val
|
||||
}
|
||||
}
|
||||
}
|
||||
return frames
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user