Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
7f0ad576
Commit
7f0ad576
authored
Jul 21, 2020
by
Ben Ye
Committed by
GitHub
Jul 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix metric naming test (#4017)
Signed-off-by:
Ben Ye
<
yb532204897@gmail.com
>
parent
0c9e2e28
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
23 deletions
+16
-23
test/metric_naming_test.go
test/metric_naming_test.go
+16
-23
No files found.
test/metric_naming_test.go
View file @
7f0ad576
package
test
package
test
import
(
import
(
"bytes"
"go/ast"
"go/ast"
"go/parser"
"go/parser"
"go/token"
"go/token"
"os"
"os"
"path/filepath"
"path/filepath"
"strconv"
"strings"
"strings"
"testing"
"testing"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil/promlint"
dto
"github.com/prometheus/client_model/go"
dto
"github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt"
"github.com/prometheus/prometheus/util/promlint"
)
)
func
TestMetricNaming
(
t
*
testing
.
T
)
{
func
TestMetricNaming
(
t
*
testing
.
T
)
{
...
@@ -27,16 +27,7 @@ func TestMetricNaming(t *testing.T) {
...
@@ -27,16 +27,7 @@ func TestMetricNaming(t *testing.T) {
}
}
if
len
(
walker
.
Metrics
)
>
0
{
if
len
(
walker
.
Metrics
)
>
0
{
l
:=
promlint
.
NewWithMetricFamilies
(
walker
.
Metrics
)
buf
:=
&
bytes
.
Buffer
{}
encoder
:=
expfmt
.
NewEncoder
(
buf
,
expfmt
.
FmtText
)
for
_
,
mf
:=
range
walker
.
Metrics
{
if
err
:=
encoder
.
Encode
(
mf
);
err
!=
nil
{
t
.
Fatalf
(
"Encoding and sending metric family: %s"
,
err
)
}
}
l
:=
promlint
.
New
(
buf
)
problems
,
err
:=
l
.
Lint
()
problems
,
err
:=
l
.
Lint
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Link found error: %s"
,
err
)
t
.
Fatalf
(
"Link found error: %s"
,
err
)
...
@@ -86,7 +77,7 @@ type metric struct {
...
@@ -86,7 +77,7 @@ type metric struct {
Metric
*
dto
.
MetricFamily
Metric
*
dto
.
MetricFamily
}
}
func
(
l
metric
)
Visit
(
n
ast
.
Node
)
ast
.
Visitor
{
func
(
l
*
metric
)
Visit
(
n
ast
.
Node
)
ast
.
Visitor
{
if
n
==
nil
{
if
n
==
nil
{
return
nil
return
nil
}
}
...
@@ -142,13 +133,20 @@ func (l metric) Visit(n ast.Node) ast.Visitor {
...
@@ -142,13 +133,20 @@ func (l metric) Visit(n ast.Node) ast.Visitor {
if
!
ok
{
if
!
ok
{
continue
continue
}
}
// remove quotes
stringLiteral
,
err
:=
strconv
.
Unquote
(
value
.
Value
)
if
err
!=
nil
{
return
l
}
switch
object
.
Name
{
switch
object
.
Name
{
case
"Subsystem"
:
case
"Subsystem"
:
subsystem
=
value
.
Value
subsystem
=
stringLiteral
case
"Name"
:
case
"Name"
:
name
=
value
.
Value
name
=
stringLiteral
case
"Help"
:
case
"Help"
:
help
=
value
.
Value
help
=
stringLiteral
}
}
}
}
...
@@ -157,12 +155,7 @@ func (l metric) Visit(n ast.Node) ast.Visitor {
...
@@ -157,12 +155,7 @@ func (l metric) Visit(n ast.Node) ast.Visitor {
return
l
return
l
}
}
var
metricName
string
metricName
:=
prometheus
.
BuildFQName
(
plugin
.
Namespace
,
subsystem
,
name
)
if
len
(
subsystem
)
>
0
{
metricName
=
strings
.
Join
([]
string
{
plugin
.
Namespace
,
subsystem
,
name
},
"_"
)
}
else
{
metricName
=
strings
.
Join
([]
string
{
plugin
.
Namespace
,
name
},
"_"
)
}
l
.
Metric
=
&
dto
.
MetricFamily
{
l
.
Metric
=
&
dto
.
MetricFamily
{
Name
:
&
metricName
,
Name
:
&
metricName
,
Help
:
&
help
,
Help
:
&
help
,
...
...
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