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
7a79b819
Commit
7a79b819
authored
Apr 12, 2017
by
John Belamaric
Committed by
GitHub
Apr 12, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #613 from coredns/err-multiple-mon-handler
middleware/metrics: allow multiple listeners
parents
2196dde9
c2629460
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
9 deletions
+35
-9
middleware/metrics/README.md
middleware/metrics/README.md
+2
-2
middleware/metrics/setup.go
middleware/metrics/setup.go
+33
-7
No files found.
middleware/metrics/README.md
View file @
7a79b819
...
@@ -49,5 +49,5 @@ prometheus localhost:9253
...
@@ -49,5 +49,5 @@ prometheus localhost:9253
# Bugs
# Bugs
When reloading, we keep the handler running, meaning that any changes to the handler
aren't picked
When reloading, we keep the handler running, meaning that any changes to the handler
's address
up. You'll need to restart CoreDNS for that to happen.
aren't picked
up. You'll need to restart CoreDNS for that to happen.
middleware/metrics/setup.go
View file @
7a79b819
...
@@ -2,7 +2,6 @@ package metrics
...
@@ -2,7 +2,6 @@ package metrics
import
(
import
(
"net"
"net"
"sync"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/middleware"
"github.com/coredns/coredns/middleware"
...
@@ -15,6 +14,8 @@ func init() {
...
@@ -15,6 +14,8 @@ func init() {
ServerType
:
"dns"
,
ServerType
:
"dns"
,
Action
:
setup
,
Action
:
setup
,
})
})
uniqAddr
=
addrs
{
a
:
make
(
map
[
string
]
int
)}
}
}
func
setup
(
c
*
caddy
.
Controller
)
error
{
func
setup
(
c
*
caddy
.
Controller
)
error
{
...
@@ -28,11 +29,14 @@ func setup(c *caddy.Controller) error {
...
@@ -28,11 +29,14 @@ func setup(c *caddy.Controller) error {
return
m
return
m
})
})
// During restarts we will keep this handler running.
for
a
,
v
:=
range
uniqAddr
.
a
{
metricsOnce
.
Do
(
func
()
{
if
v
==
todo
{
c
.
OncePerServerBlock
(
m
.
OnStartup
)
// During restarts we will keep this handler running, BUG.
c
.
OnFinalShutdown
(
m
.
OnShutdown
)
c
.
OncePerServerBlock
(
m
.
OnStartup
)
})
}
uniqAddr
.
a
[
a
]
=
done
}
c
.
OnFinalShutdown
(
m
.
OnShutdown
)
return
nil
return
nil
}
}
...
@@ -43,6 +47,10 @@ func prometheusParse(c *caddy.Controller) (*Metrics, error) {
...
@@ -43,6 +47,10 @@ func prometheusParse(c *caddy.Controller) (*Metrics, error) {
err
error
err
error
)
)
defer
func
()
{
uniqAddr
.
SetAddress
(
met
.
Addr
)
}()
for
c
.
Next
()
{
for
c
.
Next
()
{
if
len
(
met
.
ZoneNames
())
>
0
{
if
len
(
met
.
ZoneNames
())
>
0
{
return
met
,
c
.
Err
(
"can only have one metrics module per server"
)
return
met
,
c
.
Err
(
"can only have one metrics module per server"
)
...
@@ -86,7 +94,25 @@ func prometheusParse(c *caddy.Controller) (*Metrics, error) {
...
@@ -86,7 +94,25 @@ func prometheusParse(c *caddy.Controller) (*Metrics, error) {
return
met
,
err
return
met
,
err
}
}
var
metricsOnce
sync
.
Once
var
uniqAddr
addrs
// Keep track on which addrs we listen, so we only start one listener.
type
addrs
struct
{
a
map
[
string
]
int
}
func
(
a
*
addrs
)
SetAddress
(
addr
string
)
{
// If already there and set to done, we've already started this listener.
if
a
.
a
[
addr
]
==
done
{
return
}
a
.
a
[
addr
]
=
todo
}
// Addr is the address the where the metrics are exported by default.
// Addr is the address the where the metrics are exported by default.
const
addr
=
"localhost:9153"
const
addr
=
"localhost:9153"
const
(
todo
=
1
done
=
2
)
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