this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

update cached directory metrics

+78 -26
+18
atproto/identity/cache_directory.go
··· 95 95 if h.IsInvalidHandle() { 96 96 return "", fmt.Errorf("can not resolve handle: %w", ErrInvalidHandle) 97 97 } 98 + start := time.Now() 98 99 entry, ok := d.handleCache.Get(h) 99 100 if ok && !d.IsHandleStale(&entry) { 100 101 handleCacheHits.Inc() 102 + handleResolution.WithLabelValues("lru", "cached").Inc() 103 + handleResolutionDuration.WithLabelValues("lru", "cached").Observe(time.Since(start).Seconds()) 101 104 return entry.DID, entry.Err 102 105 } 103 106 handleCacheMisses.Inc() ··· 107 110 val, loaded := d.handleLookupChans.LoadOrStore(h.String(), res) 108 111 if loaded { 109 112 handleRequestsCoalesced.Inc() 113 + handleResolution.WithLabelValues("lru", "coalesced").Inc() 114 + handleResolutionDuration.WithLabelValues("lru", "coalesced").Observe(time.Since(start).Seconds()) 110 115 // Wait for the result from the pending request 111 116 select { 112 117 case <-val.(chan struct{}): ··· 130 135 close(res) 131 136 132 137 if newEntry.Err != nil { 138 + handleResolution.WithLabelValues("lru", "error").Inc() 139 + handleResolutionDuration.WithLabelValues("lru", "error").Observe(time.Since(start).Seconds()) 133 140 return "", newEntry.Err 134 141 } 135 142 if newEntry.DID != "" { 143 + handleResolution.WithLabelValues("lru", "success").Inc() 144 + handleResolutionDuration.WithLabelValues("lru", "success").Observe(time.Since(start).Seconds()) 136 145 return newEntry.DID, nil 137 146 } 138 147 return "", fmt.Errorf("unexpected control-flow error") ··· 169 178 } 170 179 171 180 func (d *CacheDirectory) LookupDIDWithCacheState(ctx context.Context, did syntax.DID) (*Identity, bool, error) { 181 + start := time.Now() 172 182 entry, ok := d.identityCache.Get(did) 173 183 if ok && !d.IsIdentityStale(&entry) { 174 184 identityCacheHits.Inc() 185 + didResolution.WithLabelValues("lru", "cached").Inc() 186 + didResolutionDuration.WithLabelValues("lru", "cached").Observe(time.Since(start).Seconds()) 175 187 return entry.Identity, true, entry.Err 176 188 } 177 189 identityCacheMisses.Inc() ··· 181 193 val, loaded := d.didLookupChans.LoadOrStore(did.String(), res) 182 194 if loaded { 183 195 identityRequestsCoalesced.Inc() 196 + didResolution.WithLabelValues("lru", "coalesced").Inc() 197 + didResolutionDuration.WithLabelValues("lru", "coalesced").Observe(time.Since(start).Seconds()) 184 198 // Wait for the result from the pending request 185 199 select { 186 200 case <-val.(chan struct{}): ··· 204 218 close(res) 205 219 206 220 if newEntry.Err != nil { 221 + didResolution.WithLabelValues("lru", "error").Inc() 222 + didResolutionDuration.WithLabelValues("lru", "error").Observe(time.Since(start).Seconds()) 207 223 return nil, false, newEntry.Err 208 224 } 209 225 if newEntry.Identity != nil { 226 + didResolution.WithLabelValues("lru", "success").Inc() 227 + didResolutionDuration.WithLabelValues("lru", "success").Observe(time.Since(start).Seconds()) 210 228 return newEntry.Identity, false, nil 211 229 } 212 230 return nil, false, fmt.Errorf("unexpected control-flow error")
+18 -26
atproto/identity/metrics.go
··· 5 5 "github.com/prometheus/client_golang/prometheus/promauto" 6 6 ) 7 7 8 - var handleCacheHits = promauto.NewCounter(prometheus.CounterOpts{ 9 - Name: "atproto_directory_handle_cache_hits", 10 - Help: "Number of cache hits for ATProto handle lookups", 11 - }) 12 - 13 - var handleCacheMisses = promauto.NewCounter(prometheus.CounterOpts{ 14 - Name: "atproto_directory_handle_cache_misses", 15 - Help: "Number of cache misses for ATProto handle lookups", 16 - }) 17 - 18 - var identityCacheHits = promauto.NewCounter(prometheus.CounterOpts{ 19 - Name: "atproto_directory_identity_cache_hits", 20 - Help: "Number of cache hits for ATProto identity lookups", 21 - }) 8 + var handleResolution = promauto.NewCounterVec(prometheus.CounterOpts{ 9 + Name: "atproto_identity_resolve_handle", 10 + Help: "ATProto handle resolutions", 11 + }, []string{"directory", "status"}) 22 12 23 - var identityCacheMisses = promauto.NewCounter(prometheus.CounterOpts{ 24 - Name: "atproto_directory_identity_cache_misses", 25 - Help: "Number of cache misses for ATProto identity lookups", 26 - }) 13 + var handleResolutionDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{ 14 + Name: "atproto_identity_resolve_handle_duration", 15 + Help: "Time to resolve a handle", 16 + Buckets: prometheus.ExponentialBucketsRange(0.001, 2, 15), 17 + }, []string{"directory", "status"}) 27 18 28 - var identityRequestsCoalesced = promauto.NewCounter(prometheus.CounterOpts{ 29 - Name: "atproto_directory_identity_requests_coalesced", 30 - Help: "Number of identity requests coalesced", 31 - }) 19 + var didResolution = promauto.NewCounterVec(prometheus.CounterOpts{ 20 + Name: "atproto_identity_resolve_did", 21 + Help: "ATProto DID resolutions", 22 + }, []string{"directory", "status"}) 32 23 33 - var handleRequestsCoalesced = promauto.NewCounter(prometheus.CounterOpts{ 34 - Name: "atproto_directory_handle_requests_coalesced", 35 - Help: "Number of handle requests coalesced", 36 - }) 24 + var didResolutionDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{ 25 + Name: "atproto_identity_resolve_did_duration", 26 + Help: "Time to resolve a DID", 27 + Buckets: prometheus.ExponentialBucketsRange(0.001, 2, 15), 28 + }, []string{"directory", "status"})
+42
atproto/identity/metrics_legacy.go
··· 1 + package identity 2 + 3 + import ( 4 + "github.com/prometheus/client_golang/prometheus" 5 + "github.com/prometheus/client_golang/prometheus/promauto" 6 + ) 7 + 8 + // DEPRECATED 9 + var handleCacheHits = promauto.NewCounter(prometheus.CounterOpts{ 10 + Name: "atproto_directory_handle_cache_hits", 11 + Help: "Number of cache hits for ATProto handle lookups", 12 + }) 13 + 14 + // DEPRECATED 15 + var handleCacheMisses = promauto.NewCounter(prometheus.CounterOpts{ 16 + Name: "atproto_directory_handle_cache_misses", 17 + Help: "Number of cache misses for ATProto handle lookups", 18 + }) 19 + 20 + // DEPRECATED 21 + var identityCacheHits = promauto.NewCounter(prometheus.CounterOpts{ 22 + Name: "atproto_directory_identity_cache_hits", 23 + Help: "Number of cache hits for ATProto identity lookups", 24 + }) 25 + 26 + // DEPRECATED 27 + var identityCacheMisses = promauto.NewCounter(prometheus.CounterOpts{ 28 + Name: "atproto_directory_identity_cache_misses", 29 + Help: "Number of cache misses for ATProto identity lookups", 30 + }) 31 + 32 + // DEPRECATED 33 + var identityRequestsCoalesced = promauto.NewCounter(prometheus.CounterOpts{ 34 + Name: "atproto_directory_identity_requests_coalesced", 35 + Help: "Number of identity requests coalesced", 36 + }) 37 + 38 + // DEPRECATED 39 + var handleRequestsCoalesced = promauto.NewCounter(prometheus.CounterOpts{ 40 + Name: "atproto_directory_handle_requests_coalesced", 41 + Help: "Number of handle requests coalesced", 42 + })