Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
a63877bd
Commit
a63877bd
authored
Sep 27, 2018
by
Daniel Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stackdriver: pattern formatting for annotations
parent
9351b56e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
23 deletions
+44
-23
pkg/tsdb/stackdriver/annotation_query.go
+41
-20
pkg/tsdb/stackdriver/annotation_query_test.go
+3
-3
No files found.
pkg/tsdb/stackdriver/annotation_query.go
View file @
a63877bd
...
...
@@ -2,6 +2,8 @@ package stackdriver
import
(
"context"
"fmt"
"strings"
"time"
"github.com/grafana/grafana/pkg/tsdb"
...
...
@@ -42,9 +44,9 @@ func (e *StackdriverExecutor) parseToAnnotations(queryRes *tsdb.QueryResult, dat
annotation
:=
make
(
map
[
string
]
string
)
annotation
[
"time"
]
=
point
.
Interval
.
EndTime
.
UTC
()
.
Format
(
time
.
RFC3339
)
annotation
[
"title"
]
=
title
annotation
[
"title"
]
=
formatAnnotationText
(
title
,
point
.
Value
.
DoubleValue
,
series
.
Metric
.
Type
,
series
.
Metric
.
Labels
,
series
.
Resource
.
Labels
)
annotation
[
"tags"
]
=
tags
annotation
[
"text"
]
=
text
annotation
[
"text"
]
=
formatAnnotationText
(
text
,
point
.
Value
.
DoubleValue
,
series
.
Metric
.
Type
,
series
.
Metric
.
Labels
,
series
.
Resource
.
Labels
)
annotations
=
append
(
annotations
,
annotation
)
}
}
...
...
@@ -76,21 +78,40 @@ func transformAnnotationToTable(data []map[string]string, result *tsdb.QueryResu
slog
.
Info
(
"anno"
,
"len"
,
len
(
data
))
}
// func (e *StackdriverExecutor) buildAnnotationQuery(tsdbQuery *tsdb.TsdbQuery) (*StackdriverQuery, error) {
// firstQuery := queryContext.Queries[0]
// metricType := query.Model.Get("metricType").MustString()
// filterParts := query.Model.Get("filters").MustArray()
// filterString := buildFilterString(metricType, filterParts)
// params := url.Values{}
// params.Add("interval.startTime", startTime.UTC().Format(time.RFC3339))
// params.Add("interval.endTime", endTime.UTC().Format(time.RFC3339))
// params.Add("filter", buildFilterString(metricType, filterParts))
// params.Add("view", "FULL")
// return &StackdriverQuery{
// RefID: firstQuery.RefID,
// Params: params,
// Target: "",
// }, nil
// }
func
formatAnnotationText
(
annotationText
string
,
pointValue
float64
,
metricType
string
,
metricLabels
map
[
string
]
string
,
resourceLabels
map
[
string
]
string
)
string
{
result
:=
legendKeyFormat
.
ReplaceAllFunc
([]
byte
(
annotationText
),
func
(
in
[]
byte
)
[]
byte
{
metaPartName
:=
strings
.
Replace
(
string
(
in
),
"{{"
,
""
,
1
)
metaPartName
=
strings
.
Replace
(
metaPartName
,
"}}"
,
""
,
1
)
metaPartName
=
strings
.
TrimSpace
(
metaPartName
)
if
metaPartName
==
"metric.type"
{
return
[]
byte
(
metricType
)
}
metricPart
:=
replaceWithMetricPart
(
metaPartName
,
metricType
)
if
metricPart
!=
nil
{
return
metricPart
}
if
metaPartName
==
"value"
{
return
[]
byte
(
fmt
.
Sprintf
(
"%f"
,
pointValue
))
}
metaPartName
=
strings
.
Replace
(
metaPartName
,
"metric.label."
,
""
,
1
)
if
val
,
exists
:=
metricLabels
[
metaPartName
];
exists
{
return
[]
byte
(
val
)
}
metaPartName
=
strings
.
Replace
(
metaPartName
,
"resource.label."
,
""
,
1
)
if
val
,
exists
:=
resourceLabels
[
metaPartName
];
exists
{
return
[]
byte
(
val
)
}
return
in
})
return
string
(
result
)
}
pkg/tsdb/stackdriver/annotation_query_test.go
View file @
a63877bd
...
...
@@ -19,14 +19,14 @@ func TestStackdriverAnnotationQuery(t *testing.T) {
res
:=
&
tsdb
.
QueryResult
{
Meta
:
simplejson
.
New
(),
RefId
:
"annotationQuery"
}
query
:=
&
StackdriverQuery
{}
err
=
executor
.
parseToAnnotations
(
res
,
data
,
query
,
"atitle
"
,
"atext
"
,
"atag"
)
err
=
executor
.
parseToAnnotations
(
res
,
data
,
query
,
"atitle
{{metric.label.instance_name}} {{value}}"
,
"atext {{resource.label.zone}}
"
,
"atag"
)
So
(
err
,
ShouldBeNil
)
Convey
(
"Should return annotations table"
,
func
()
{
So
(
len
(
res
.
Tables
),
ShouldEqual
,
1
)
So
(
len
(
res
.
Tables
[
0
]
.
Rows
),
ShouldEqual
,
9
)
So
(
res
.
Tables
[
0
]
.
Rows
[
0
][
1
],
ShouldEqual
,
"atitle"
)
So
(
res
.
Tables
[
0
]
.
Rows
[
0
][
3
],
ShouldEqual
,
"atext"
)
So
(
res
.
Tables
[
0
]
.
Rows
[
0
][
1
],
ShouldEqual
,
"atitle
collector-asia-east-1 9.856650
"
)
So
(
res
.
Tables
[
0
]
.
Rows
[
0
][
3
],
ShouldEqual
,
"atext
asia-east1-a
"
)
})
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment