mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-04 10:11:10 +01:00 
			
		
		
		
	registry cache_miss logic (#3578)
Signed-off-by: zouyee <zounyee1989@gmail.com>
This commit is contained in:
		
							parent
							
								
									908508a9bd
								
							
						
					
					
						commit
						99e7c3dee7
					
				
							
								
								
									
										1
									
								
								plugin/cache/handler.go
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								plugin/cache/handler.go
									
									
									
									
										vendored
									
									
								
							@ -114,6 +114,7 @@ func (c *Cache) getIgnoreTTL(now time.Time, state request.Request, server string
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		return i.(*item)
 | 
							return i.(*item)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						cacheMisses.WithLabelValues(server).Inc()
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -5,6 +5,7 @@ import (
 | 
				
			|||||||
	"io/ioutil"
 | 
						"io/ioutil"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -223,3 +224,39 @@ example.com:0 {
 | 
				
			|||||||
		t.Errorf("Expected value %s for %s, but got %s", "", metricName, got)
 | 
							t.Errorf("Expected value %s for %s, but got %s", "", metricName, got)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestMetricsAvailable(t *testing.T) {
 | 
				
			||||||
 | 
						procMetric := "coredns_build_info"
 | 
				
			||||||
 | 
						procCache := "coredns_cache_size"
 | 
				
			||||||
 | 
						procCacheMiss := "coredns_cache_misses_total"
 | 
				
			||||||
 | 
						procForward := "coredns_dns_request_duration_seconds"
 | 
				
			||||||
 | 
						corefileWithMetrics := `
 | 
				
			||||||
 | 
						.:0 {
 | 
				
			||||||
 | 
							prometheus localhost:0
 | 
				
			||||||
 | 
							cache
 | 
				
			||||||
 | 
							forward . 8.8.8.8 {
 | 
				
			||||||
 | 
					           force_tcp
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}`
 | 
				
			||||||
 | 
						inst, _, tcp, err := CoreDNSServerAndPorts(corefileWithMetrics)
 | 
				
			||||||
 | 
						defer inst.Stop()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							if strings.Contains(err.Error(), inUse) {
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							t.Errorf("Could not get service instance: %s", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						// send a query and check we can scrap corresponding metrics
 | 
				
			||||||
 | 
						cl := dns.Client{Net: "tcp"}
 | 
				
			||||||
 | 
						m := new(dns.Msg)
 | 
				
			||||||
 | 
						m.SetQuestion("www.example.org.", dns.TypeA)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if _, _, err := cl.Exchange(m, tcp); err != nil {
 | 
				
			||||||
 | 
							t.Fatalf("Could not send message: %s", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// we should have metrics from forward, cache, and metrics itself
 | 
				
			||||||
 | 
						if err := collectMetricsInfo(metrics.ListenAddr, procMetric, procCache, procCacheMiss, procForward); err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Could not scrap one of expected stats : %s", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user