Skip to content

Commit ddd035b

Browse files
committed
Metric name rule creation updated
1 parent 28a979b commit ddd035b

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

datasource.go

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"fmt"
99
"log"
1010
"regexp"
11-
"strings"
11+
"sort"
1212
"time"
1313

1414
"github.com/davecgh/go-spew/spew"
@@ -385,6 +385,7 @@ type responseAndQuery struct {
385385

386386
func (o *OCIDatasource) queryResponse(ctx context.Context, tsdbReq *datasource.DatasourceRequest) (*datasource.DatasourceResponse, error) {
387387
results := make([]responseAndQuery, 0, len(tsdbReq.Queries))
388+
388389
for _, query := range tsdbReq.Queries {
389390
var ts GrafanaOCIRequest
390391
json.Unmarshal([]byte(query.ModelJson), &ts)
@@ -437,24 +438,33 @@ func (o *OCIDatasource) queryResponse(ctx context.Context, tsdbReq *datasource.D
437438
Name: *(item.Name),
438439
}
439440
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)
444448
}
449+
dimensionKeys[i] = key
450+
i++
445451
}
452+
446453
// if there isn't a human readable name fallback to resourceId
447454
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)
457466
}
467+
458468
p := make([]*datasource.Point, 0, len(item.AggregatedDatapoints))
459469
for _, metric := range item.AggregatedDatapoints {
460470
point := &datasource.Point{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "oci-grafana-plugin",
33
"private": true,
4-
"version": "1.0.2",
4+
"version": "1.0.3",
55
"description": "",
66
"main": "index.js",
77
"scripts": {

plugin.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
{"name": "GitHub", "url": "https://github.com/oracle/oci-grafana-plugin"},
2727
{"name": "MIT License", "url": "https://github.com/oracle/oci-grafana-plugin"}
2828
],
29-
"version": "1.0.2",
30-
"updated": "2019-01-23"
29+
"version": "1.0.3",
30+
"updated": "2019-09-24"
3131
},
3232

3333
"dependencies": {

src/plugin.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
{"name": "GitHub", "url": "https://github.com/oracle/oci-grafana-plugin"},
2727
{"name": "UPL", "url": "https://oss.oracle.com/licenses/upl"}
2828
],
29-
"version": "1.0.2",
30-
"updated": "2019-01-23"
29+
"version": "1.0.3",
30+
"updated": "2019-09-24"
3131
},
3232

3333
"dependencies": {

0 commit comments

Comments
 (0)