fork of indigo with slightly nicer lexgen

automod: visual helper metrics

Changed files
+44
automod
+9
automod/visual/abyss_client.go
··· 8 8 "io" 9 9 "log/slog" 10 10 "net/http" 11 + "time" 11 12 12 13 lexutil "github.com/bluesky-social/indigo/lex/util" 13 14 "github.com/bluesky-social/indigo/util" ··· 56 57 req.Header.Set("x-ratelimit-bypass", ac.RatelimitBypass) 57 58 } 58 59 60 + start := time.Now() 61 + defer func() { 62 + duration := time.Since(start) 63 + abyssAPIDuration.Observe(duration.Seconds()) 64 + }() 65 + 59 66 req = req.WithContext(ctx) 60 67 res, err := ac.Client.Do(req) 61 68 if err != nil { 62 69 return nil, fmt.Errorf("abyss request failed: %v", err) 63 70 } 64 71 defer res.Body.Close() 72 + 73 + abyssAPICount.WithLabelValues(fmt.Sprint(res.StatusCode)).Inc() 65 74 if res.StatusCode != 200 { 66 75 return nil, fmt.Errorf("abyss request failed statusCode=%d", res.StatusCode) 67 76 }
+9
automod/visual/hiveai_client.go
··· 9 9 "log/slog" 10 10 "mime/multipart" 11 11 "net/http" 12 + "time" 12 13 13 14 lexutil "github.com/bluesky-social/indigo/lex/util" 14 15 "github.com/bluesky-social/indigo/util" ··· 182 183 return nil, err 183 184 } 184 185 186 + start := time.Now() 187 + defer func() { 188 + duration := time.Since(start) 189 + hiveAPIDuration.Observe(duration.Seconds()) 190 + }() 191 + 185 192 req.Header.Set("Authorization", fmt.Sprintf("Token %s", hal.ApiToken)) 186 193 req.Header.Add("Content-Type", writer.FormDataContentType()) 187 194 req.Header.Set("Accept", "application/json") ··· 193 200 return nil, fmt.Errorf("HiveAI request failed: %v", err) 194 201 } 195 202 defer res.Body.Close() 203 + 204 + hiveAPICount.WithLabelValues(fmt.Sprint(res.StatusCode)).Inc() 196 205 if res.StatusCode != 200 { 197 206 return nil, fmt.Errorf("HiveAI request failed statusCode=%d", res.StatusCode) 198 207 }
+26
automod/visual/metrics.go
··· 1 + package visual 2 + 3 + import ( 4 + "github.com/prometheus/client_golang/prometheus" 5 + "github.com/prometheus/client_golang/prometheus/promauto" 6 + ) 7 + 8 + var hiveAPIDuration = promauto.NewHistogram(prometheus.HistogramOpts{ 9 + Name: "automod_hive_api_duration_sec", 10 + Help: "Duration of Hive image auto-labeling API calls", 11 + }) 12 + 13 + var hiveAPICount = promauto.NewCounterVec(prometheus.CounterOpts{ 14 + Name: "automod_hive_api_count", 15 + Help: "Number of Hive image auto-labeling API calls, by HTTP status code", 16 + }, []string{"status"}) 17 + 18 + var abyssAPIDuration = promauto.NewHistogram(prometheus.HistogramOpts{ 19 + Name: "automod_abyss_api_duration_sec", 20 + Help: "Duration of abyss image scanning API call", 21 + }) 22 + 23 + var abyssAPICount = promauto.NewCounterVec(prometheus.CounterOpts{ 24 + Name: "automod_abyss_api_count", 25 + Help: "Number of abyss image scanning API calls, by HTTP status code", 26 + }, []string{"status"})