mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 10:13:14 -04:00 
			
		
		
		
	plugin/metrics: add MustRegister function (#1648)
This registers the Collectors iff the metrics plugin has been loaded. Safes a bunch of code in each and every plugin's setup code.
This commit is contained in:
		
							
								
								
									
										16
									
								
								plugin/cache/setup.go
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										16
									
								
								plugin/cache/setup.go
									
									
									
									
										vendored
									
									
								
							| @@ -32,18 +32,10 @@ func setup(c *caddy.Controller) error { | ||||
|  | ||||
| 	c.OnStartup(func() error { | ||||
| 		once.Do(func() { | ||||
| 			m := dnsserver.GetConfig(c).Handler("prometheus") | ||||
| 			if m == nil { | ||||
| 				return | ||||
| 			} | ||||
| 			if x, ok := m.(*metrics.Metrics); ok { | ||||
| 				x.MustRegister(cacheSize) | ||||
| 				x.MustRegister(cacheCapacity) | ||||
| 				x.MustRegister(cacheHits) | ||||
| 				x.MustRegister(cacheMisses) | ||||
| 				x.MustRegister(cachePrefetches) | ||||
| 				x.MustRegister(cacheDrops) | ||||
| 			} | ||||
| 			metrics.MustRegister(c, | ||||
| 				cacheSize, cacheCapacity, | ||||
| 				cacheHits, cacheMisses, | ||||
| 				cachePrefetches, cacheDrops) | ||||
| 		}) | ||||
| 		return nil | ||||
| 	}) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user