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
747513d4
Unverified
Commit
747513d4
authored
Oct 01, 2020
by
Marcus Efraimsson
Committed by
GitHub
Oct 01, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Plugins: Fix loading of backend plugins (#27951)
Ref #27921
parent
298ac20d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
30 deletions
+34
-30
pkg/infra/metrics/metrics.go
+0
-27
pkg/infra/metrics/metricutil/utils.go
+31
-0
pkg/infra/metrics/metricutil/utils_test.go
+1
-1
pkg/models/datasource_cache.go
+2
-2
No files found.
pkg/infra/metrics/metrics.go
View file @
747513d4
package
metrics
import
(
"errors"
"fmt"
"runtime"
"strings"
"github.com/prometheus/client_golang/prometheus"
...
...
@@ -592,27 +589,3 @@ func newCounterStartingAtZero(opts prometheus.CounterOpts, labelValues ...string
return
counter
}
// SanitizeLabelName removes all invalid chars from the label name.
// If the label name is empty or contains only invalid chars, it
// will return an error.
func
SanitizeLabelName
(
name
string
)
(
string
,
error
)
{
if
len
(
name
)
==
0
{
return
""
,
errors
.
New
(
"label name cannot be empty"
)
}
out
:=
strings
.
Builder
{}
for
i
,
b
:=
range
name
{
if
(
b
>=
'a'
&&
b
<=
'z'
)
||
(
b
>=
'A'
&&
b
<=
'Z'
)
||
b
==
'_'
||
(
b
>=
'0'
&&
b
<=
'9'
&&
i
>
0
)
{
out
.
WriteRune
(
b
)
}
else
if
b
==
' '
{
out
.
WriteRune
(
'_'
)
}
}
if
out
.
Len
()
==
0
{
return
""
,
fmt
.
Errorf
(
"label name only contains invalid chars: %q"
,
name
)
}
return
out
.
String
(),
nil
}
pkg/infra/metrics/metricutil/utils.go
0 → 100644
View file @
747513d4
package
metricutil
import
(
"errors"
"fmt"
"strings"
)
// SanitizeLabelName removes all invalid chars from the label name.
// If the label name is empty or contains only invalid chars, it
// will return an error.
func
SanitizeLabelName
(
name
string
)
(
string
,
error
)
{
if
len
(
name
)
==
0
{
return
""
,
errors
.
New
(
"label name cannot be empty"
)
}
out
:=
strings
.
Builder
{}
for
i
,
b
:=
range
name
{
if
(
b
>=
'a'
&&
b
<=
'z'
)
||
(
b
>=
'A'
&&
b
<=
'Z'
)
||
b
==
'_'
||
(
b
>=
'0'
&&
b
<=
'9'
&&
i
>
0
)
{
out
.
WriteRune
(
b
)
}
else
if
b
==
' '
{
out
.
WriteRune
(
'_'
)
}
}
if
out
.
Len
()
==
0
{
return
""
,
fmt
.
Errorf
(
"label name only contains invalid chars: %q"
,
name
)
}
return
out
.
String
(),
nil
}
pkg/infra/metrics/metrics_test.go
→
pkg/infra/metrics/metric
util/util
s_test.go
View file @
747513d4
package
metric
s
package
metric
util
import
(
"testing"
...
...
pkg/models/datasource_cache.go
View file @
747513d4
...
...
@@ -10,7 +10,7 @@ import (
"sync"
"time"
"github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/infra/metrics
/metricutil
"
"github.com/grafana/grafana/pkg/setting"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
...
...
@@ -73,7 +73,7 @@ type dataSourceTransport struct {
func
instrumentRoundtrip
(
datasourceName
string
,
next
http
.
RoundTripper
)
promhttp
.
RoundTripperFunc
{
return
promhttp
.
RoundTripperFunc
(
func
(
r
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
datasourceLabelName
,
err
:=
metric
s
.
SanitizeLabelName
(
datasourceName
)
datasourceLabelName
,
err
:=
metric
util
.
SanitizeLabelName
(
datasourceName
)
// if the datasource named cannot be turned into a prometheus
// label we will skip instrumenting these metrics.
if
err
!=
nil
{
...
...
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