-
Notifications
You must be signed in to change notification settings - Fork 1
feat(metrics): add Prometheus metrics expansion with DNS-specific buckets #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
29aef65
feat(metrics): add DNS-specific Prometheus metrics and derived metric…
poyrazK a98f618
feat(metrics): add rate limited counter and DNSSEC key stats collection
poyrazK 39ae3b7
feat(server): add NOTIFY, AXFR, cache hit/miss and recursive resoluti…
poyrazK 1f04ea4
fix: address review findings - fix ZoneRecordRepo types, unexport Key…
poyrazK b884635
fix: add debug logging and implement RecordsTotal metric
poyrazK cef1974
fix(lint): address golangci-lint findings - ctx propagation, unexport…
poyrazK 37fd37e
fix(lint): add nolint:revive for unexported return type in CollectKey…
poyrazK 499672f
test: add CollectKeyStats edge case test and ZoneRecordCounter unit t…
poyrazK d0f4662
fix: address remaining review findings - KeyStats export, collect gua…
poyrazK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -251,6 +251,29 @@ func (s *Server) automateDNSSEC() { | |
| s.Logger.Error("DNSSEC automation failed for zone", "zone", z.Name, "error", errAutomate) | ||
| } | ||
| } | ||
|
|
||
| // Update DNSSEC key metrics after automation | ||
| s.updateDNSSECMetrics(ctx) | ||
| } | ||
|
|
||
| func (s *Server) updateDNSSECMetrics(ctx context.Context) { | ||
| if s.DNSSEC == nil { | ||
| return | ||
| } | ||
| stats, err := s.DNSSEC.CollectKeyStats(ctx) | ||
| if err != nil { | ||
| s.Logger.Debug("failed to collect DNSSEC key stats", "error", err) | ||
| return | ||
| } | ||
| metrics.DNSSECKeysTotal.Reset() | ||
| metrics.DNSSECKeysAgeSeconds.Reset() | ||
| signedZones := 0 | ||
| for _, st := range stats { | ||
| metrics.DNSSECKeysTotal.WithLabelValues(st.ZoneName, st.KeyType, fmt.Sprintf("%d", st.Algorithm)).Set(1) | ||
| metrics.DNSSECKeysAgeSeconds.WithLabelValues(st.ZoneName, st.KeyType).Set(st.AgeSeconds) | ||
| signedZones++ | ||
| } | ||
| metrics.DNSSECZonesSigned.Set(float64(signedZones)) | ||
| } | ||
|
Comment on lines
+259
to
277
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
♻️ Proposed fix metrics.DNSSECKeysTotal.Reset()
metrics.DNSSECKeysAgeSeconds.Reset()
- signedZones := 0
+ zoneSet := make(map[string]struct{}, len(stats))
+ oldestAge := make(map[string]float64) // key: zone|key_type
for _, st := range stats {
- metrics.DNSSECKeysTotal.WithLabelValues(st.ZoneName, st.KeyType, fmt.Sprintf("%d", st.Algorithm)).Set(1)
- metrics.DNSSECKeysAgeSeconds.WithLabelValues(st.ZoneName, st.KeyType).Set(st.AgeSeconds)
- signedZones++
+ metrics.DNSSECKeysTotal.WithLabelValues(st.ZoneName, st.KeyType, fmt.Sprintf("%d", st.Algorithm)).Inc()
+ k := st.ZoneName + "|" + st.KeyType
+ if cur, ok := oldestAge[k]; !ok || st.AgeSeconds > cur {
+ oldestAge[k] = st.AgeSeconds
+ }
+ zoneSet[st.ZoneID] = struct{}{}
}
- metrics.DNSSECZonesSigned.Set(float64(signedZones))
+ for k, age := range oldestAge {
+ parts := strings.SplitN(k, "|", 2)
+ metrics.DNSSECKeysAgeSeconds.WithLabelValues(parts[0], parts[1]).Set(age)
+ }
+ metrics.DNSSECZonesSigned.Set(float64(len(zoneSet)))🤖 Prompt for AI Agents |
||
|
|
||
| // startInvalidationListener listens for cache invalidation events from Redis pub/sub. | ||
|
|
@@ -821,6 +844,7 @@ func (s *Server) sendAXFRRecord(conn net.Conn, id uint16, q packet.DNSQuestion, | |
| } | ||
| s.Logger.Debug("AXFR sent packet", "index", index, "type", pRec.Type) | ||
| packet.PutBuffer(resBuffer) | ||
| metrics.AXFRBytesTotal.Add(float64(len(fullResp))) | ||
| } | ||
|
|
||
| // sendTCPError sends a TCP DNS error response with the given RCODE. | ||
|
|
@@ -944,17 +968,20 @@ func (s *Server) handlePacket(ctx context.Context, data []byte, srcAddr interfac | |
|
|
||
| if data, found := s.Cache.GetInto(cacheKey, request.Header.ID); found { | ||
| metrics.CacheOperations.WithLabelValues("l1", "hit").Inc() | ||
| metrics.RecordCacheHit() | ||
| metrics.QueriesTotal.WithLabelValues(qTypeLabel, "0", protocol).Inc() | ||
| metrics.QueryDuration.WithLabelValues("cache_l1").Observe(time.Since(start).Seconds()) | ||
| err := sendFn(data) | ||
| lock.Unlock() | ||
| return err | ||
| } | ||
| metrics.CacheOperations.WithLabelValues("l1", "miss").Inc() | ||
| metrics.RecordCacheMiss() | ||
|
|
||
| if s.Redis != nil { | ||
| if data, remainingTTL, found := s.Redis.GetWithTTL(ctx, cacheKey); found { | ||
| metrics.CacheOperations.WithLabelValues("l2", "hit").Inc() | ||
| metrics.RecordCacheHit() | ||
| metrics.QueriesTotal.WithLabelValues(qTypeLabel, "0", protocol).Inc() | ||
| metrics.QueryDuration.WithLabelValues("cache_l2").Observe(time.Since(start).Seconds()) | ||
| // Rewrite Transaction ID (data is a copy from Redis, safe to mutate) | ||
|
|
@@ -969,6 +996,10 @@ func (s *Server) handlePacket(ctx context.Context, data []byte, srcAddr interfac | |
| } | ||
| s.Cache.Set(cacheKey, data, remainingTTL) | ||
| cachedData = data | ||
| } else if s.Redis != nil { | ||
| // Redis was checked but key not found = L2 miss | ||
| metrics.CacheOperations.WithLabelValues("l2", "miss").Inc() | ||
| metrics.RecordCacheMiss() | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1069,6 +1100,7 @@ func (s *Server) handlePacket(ctx context.Context, data []byte, srcAddr interfac | |
| qTypeStr := queryTypeToRecordType(q.QType) | ||
| records, errRepo := s.Repo.GetRecords(ctx, q.Name, qTypeStr, clientIP) | ||
| metrics.QueryDuration.WithLabelValues("database").Observe(time.Since(dbStart).Seconds()) | ||
| metrics.RecordCacheMiss() // DB lookup is a cache miss for ratio purposes | ||
|
|
||
| if errRepo == nil && len(records) > 0 { | ||
| for _, rec := range records { | ||
|
|
@@ -1303,6 +1335,7 @@ func (s *Server) handleNotify(ctx context.Context, request *packet.DNSPacket, cl | |
| return nil | ||
| } | ||
| s.Logger.Info("received NOTIFY", "zone", request.Questions[0].Name, "from", clientIP) | ||
| metrics.NotifiesTotal.WithLabelValues(request.Questions[0].Name, "accepted").Inc() | ||
|
|
||
| response := packet.NewDNSPacket() | ||
| response.Header.ID = request.Header.ID | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.