|
8 | 8 | "fmt" |
9 | 9 | "log" |
10 | 10 | "regexp" |
11 | | - "strings" |
| 11 | + "sort" |
12 | 12 | "time" |
13 | 13 |
|
14 | 14 | "github.com/davecgh/go-spew/spew" |
@@ -385,6 +385,7 @@ type responseAndQuery struct { |
385 | 385 |
|
386 | 386 | func (o *OCIDatasource) queryResponse(ctx context.Context, tsdbReq *datasource.DatasourceRequest) (*datasource.DatasourceResponse, error) { |
387 | 387 | results := make([]responseAndQuery, 0, len(tsdbReq.Queries)) |
| 388 | + |
388 | 389 | for _, query := range tsdbReq.Queries { |
389 | 390 | var ts GrafanaOCIRequest |
390 | 391 | json.Unmarshal([]byte(query.ModelJson), &ts) |
@@ -437,24 +438,33 @@ func (o *OCIDatasource) queryResponse(ctx context.Context, tsdbReq *datasource.D |
437 | 438 | Name: *(item.Name), |
438 | 439 | } |
439 | 440 | var re = regexp.MustCompile(`(?m)\w+Name`) |
440 | | - for k, v := range item.Dimensions { |
441 | | - o.logger.Debug(k) |
442 | | - if re.MatchString(k) { |
443 | | - t.Name = fmt.Sprintf("%s, {%s}", t.Name, v) |
| 441 | + dimensionKeys := make([]string, len(item.Dimensions)) |
| 442 | + i := 0 |
| 443 | + |
| 444 | + for key, dimension := range item.Dimensions { |
| 445 | + o.logger.Debug(key) |
| 446 | + if re.MatchString(key) { |
| 447 | + t.Name = fmt.Sprintf("%s, {%s}", t.Name, dimension) |
444 | 448 | } |
| 449 | + dimensionKeys[i] = key |
| 450 | + i++ |
445 | 451 | } |
| 452 | + |
446 | 453 | // if there isn't a human readable name fallback to resourceId |
447 | 454 | if t.Name == *(item).Name { |
448 | | - resourceID := item.Dimensions["resourceId"] |
449 | | - id := resourceID[strings.LastIndex(resourceID, "."):] |
450 | | - display := resourceID[0:strings.LastIndex(resourceID, ".")] + id[0:4] + "..." + id[len(id)-6:] |
451 | | - t.Name = fmt.Sprintf("%s, {%s}", t.Name, display) |
452 | | - } |
453 | | - // if the namespace is loadbalancer toss on the Ad name to match the console |
454 | | - if *(item.Namespace) == "oci_lbaas" { |
455 | | - availabilityDomain := item.Dimensions["availabilityDomain"] |
456 | | - t.Name = fmt.Sprintf("%s, %s", t.Name, availabilityDomain) |
| 455 | + var preDisplayName string = "" |
| 456 | + sort.Strings(dimensionKeys) |
| 457 | + for _, dimensionKey := range dimensionKeys { |
| 458 | + if preDisplayName == "" { |
| 459 | + preDisplayName = item.Dimensions[dimensionKey] |
| 460 | + } else { |
| 461 | + preDisplayName = preDisplayName + ", " + item.Dimensions[dimensionKey] |
| 462 | + } |
| 463 | + } |
| 464 | + |
| 465 | + t.Name = fmt.Sprintf("%s, {%s}", t.Name, preDisplayName) |
457 | 466 | } |
| 467 | + |
458 | 468 | p := make([]*datasource.Point, 0, len(item.AggregatedDatapoints)) |
459 | 469 | for _, metric := range item.AggregatedDatapoints { |
460 | 470 | point := &datasource.Point{ |
|
0 commit comments