forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
98 lines (88 loc) · 3.2 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package dns
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/coreos/go-etcd/etcd"
"github.com/prometheus/client_golang/prometheus"
backendetcd "github.com/skynetservices/skydns/backends/etcd"
"github.com/skynetservices/skydns/server"
)
// NewServerDefaults returns the default SkyDNS server configuration for a DNS server.
func NewServerDefaults() (*server.Config, error) {
config := &server.Config{
Domain: "cluster.local.",
Local: "openshift.default.svc.cluster.local.",
}
return config, server.SetDefaults(config)
}
// ListenAndServe starts a DNS server that exposes services and values stored in etcd (if etcdclient
// is not nil). It will block until the server exits.
// TODO: hoist the service accessor out of this package so it can be reused.
func ListenAndServe(config *server.Config, client *client.Client, etcdclient *etcd.Client) error {
stop := make(chan struct{})
accessor := NewCachedServiceAccessor(client, stop)
resolver := NewServiceResolver(config, accessor, client, openshiftFallback)
resolvers := server.FirstBackend{resolver}
if etcdclient != nil {
resolvers = append(resolvers, backendetcd.NewBackend(etcdclient, &backendetcd.Config{
Ttl: config.Ttl,
Priority: config.Priority,
}))
}
server.Metrics()
s := server.New(resolvers, config)
defer close(stop)
return s.Run()
}
func openshiftFallback(name string, exact bool) (string, bool) {
if name == "openshift.default.svc" {
return "kubernetes.default.svc.", true
}
if name == "_endpoints.openshift.default.svc" {
return "_endpoints.kubernetes.default.", true
}
return "", false
}
// counter is a SkyDNS compatible Counter
type counter struct {
prometheus.Counter
}
// newCounter registers a prometheus counter and wraps it to match SkyDNS
func newCounter(c prometheus.Counter) server.Counter {
prometheus.MustRegister(c)
return counter{c}
}
// Inc increases the counter with the given value
func (c counter) Inc(val int64) {
c.Counter.Add(float64(val))
}
// Add prometheus logging to SkyDNS
func init() {
server.StatsForwardCount = newCounter(prometheus.NewCounter(prometheus.CounterOpts{
Name: "dns_forward_count",
Help: "Counter of DNS requests forwarded",
}))
server.StatsLookupCount = newCounter(prometheus.NewCounter(prometheus.CounterOpts{
Name: "dns_lookup_count",
Help: "Counter of DNS lookups performed",
}))
server.StatsRequestCount = newCounter(prometheus.NewCounter(prometheus.CounterOpts{
Name: "dns_request_count",
Help: "Counter of DNS requests made",
}))
server.StatsDnssecOkCount = newCounter(prometheus.NewCounter(prometheus.CounterOpts{
Name: "dns_dnssec_ok_count",
Help: "Counter of DNSSEC requests that were valid",
}))
server.StatsDnssecCacheMiss = newCounter(prometheus.NewCounter(prometheus.CounterOpts{
Name: "dns_dnssec_cache_miss_count",
Help: "Counter of DNSSEC requests that missed the cache",
}))
server.StatsNameErrorCount = newCounter(prometheus.NewCounter(prometheus.CounterOpts{
Name: "dns_name_error_count",
Help: "Counter of DNS requests resulting in a name error",
}))
server.StatsNoDataCount = newCounter(prometheus.NewCounter(prometheus.CounterOpts{
Name: "dns_no_data_count",
Help: "Counter of DNS requests that contained no data",
}))
}