mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 02:03:20 -04:00 
			
		
		
		
	plugin/autopath: Add metrics and remove log line (#1143)
* plugin/autopath: Add namespace selector and metrics Add a namespace, so autopathing only is performed in this namespace. This will make caching work for the cluster again. Also export metrics that we've done a successful autopath * dont shadow * Fix * Back the namespacing changes
This commit is contained in:
		| @@ -24,6 +24,12 @@ Currently the following set of plugin has implemented *autopath*: | ||||
| * *kubernetes* | ||||
| * *erratic* | ||||
|  | ||||
| ## Metrics | ||||
|   | ||||
| If monitoring is enabled (via the *prometheus* directive) then the following metric is exported: | ||||
|   | ||||
| * `coredns_autopath_success_count_total{}` - counter of successfully autopath-ed queries. | ||||
|  | ||||
| ## Examples | ||||
|  | ||||
| ~~~ | ||||
| @@ -41,5 +47,5 @@ Use the search path dynamically retrieved from the kubernetes plugin. | ||||
|  | ||||
| ## Bugs | ||||
|  | ||||
| When the *cache* plugin is enabled it is possible for pods in different namespaces to get the | ||||
| same answer. | ||||
| Replies from this plugin are not cached, as the *cache* plugin is configured after this one (see | ||||
| plugin.cfg). | ||||
|   | ||||
| @@ -32,8 +32,6 @@ func (m Plugins ) AutoPath(state request.Request) []string { | ||||
| package autopath | ||||
|  | ||||
| import ( | ||||
| 	"log" | ||||
|  | ||||
| 	"github.com/coredns/coredns/plugin" | ||||
| 	"github.com/coredns/coredns/plugin/pkg/dnsutil" | ||||
| 	"github.com/coredns/coredns/plugin/pkg/nonwriter" | ||||
| @@ -76,7 +74,6 @@ func (a *AutoPath) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms | ||||
| 	} | ||||
|  | ||||
| 	if len(searchpath) == 0 { | ||||
| 		log.Printf("[WARNING] No search path available for autopath") | ||||
| 		return plugin.NextOrFailure(a.Name(), a.Next, ctx, w, r) | ||||
| 	} | ||||
|  | ||||
| @@ -87,7 +84,7 @@ func (a *AutoPath) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms | ||||
| 	origQName := state.QName() | ||||
|  | ||||
| 	// Establish base name of the query. I.e what was originally asked. | ||||
| 	base, err := dnsutil.TrimZone(state.QName(), searchpath[0]) // TODO(miek): we loose the original case of the query here. | ||||
| 	base, err := dnsutil.TrimZone(state.QName(), searchpath[0]) | ||||
| 	if err != nil { | ||||
| 		return dns.RcodeServerFailure, err | ||||
| 	} | ||||
| @@ -128,6 +125,7 @@ func (a *AutoPath) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms | ||||
|  | ||||
| 		// Write whatever non-nxdomain answer we've found. | ||||
| 		w.WriteMsg(msg) | ||||
| 		AutoPathCount.WithLabelValues().Add(1) | ||||
| 		return rcode, err | ||||
|  | ||||
| 	} | ||||
|   | ||||
							
								
								
									
										29
									
								
								plugin/autopath/metrics.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								plugin/autopath/metrics.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | ||||
| package autopath | ||||
|  | ||||
| import ( | ||||
| 	"sync" | ||||
|  | ||||
| 	"github.com/coredns/coredns/plugin" | ||||
|  | ||||
| 	"github.com/prometheus/client_golang/prometheus" | ||||
| ) | ||||
|  | ||||
| // Metrics for autopath. | ||||
| var ( | ||||
| 	AutoPathCount = prometheus.NewCounterVec(prometheus.CounterOpts{ | ||||
| 		Namespace: plugin.Namespace, | ||||
| 		Subsystem: "autopath", | ||||
| 		Name:      "success_count_total", | ||||
| 		Help:      "Counter of requests that did autopath.", | ||||
| 	}, []string{}) | ||||
| ) | ||||
|  | ||||
| // OnStartupMetrics sets up the metrics on startup. | ||||
| func OnStartupMetrics() error { | ||||
| 	metricsOnce.Do(func() { | ||||
| 		prometheus.MustRegister(AutoPathCount) | ||||
| 	}) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| var metricsOnce sync.Once | ||||
| @@ -26,6 +26,8 @@ func setup(c *caddy.Controller) error { | ||||
| 		return plugin.Error("autopath", err) | ||||
| 	} | ||||
|  | ||||
| 	c.OnStartup(OnStartupMetrics) | ||||
|  | ||||
| 	// Do this in OnStartup, so all plugin has been initialized. | ||||
| 	c.OnStartup(func() error { | ||||
| 		m := dnsserver.GetConfig(c).Handler(mw) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user