@@ -14,11 +14,10 @@ import (
1414)
1515
1616// recordingMetrics is a metrics.Metrics implementation that captures emitted
17- // metrics so tests can assert on telemetry. It is safe for concurrent use.
17+ // counters so tests can assert on telemetry. It is safe for concurrent use.
1818type recordingMetrics struct {
19- mu sync.Mutex
20- increments []recordedMetric
21- counters []recordedMetric
19+ mu sync.Mutex
20+ counters []recordedMetric
2221}
2322
2423type recordedMetric struct {
@@ -27,11 +26,7 @@ type recordedMetric struct {
2726 value int64
2827}
2928
30- func (m * recordingMetrics ) Increment (key string , tags map [string ]string ) {
31- m .mu .Lock ()
32- defer m .mu .Unlock ()
33- m .increments = append (m .increments , recordedMetric {key : key , tags : tags , value : 1 })
34- }
29+ func (m * recordingMetrics ) Increment (_ string , _ map [string ]string ) {}
3530
3631func (m * recordingMetrics ) Counter (key string , tags map [string ]string , value int64 ) {
3732 m .mu .Lock ()
@@ -55,18 +50,6 @@ func (m *recordingMetrics) counter(key string) (recordedMetric, bool) {
5550 return recordedMetric {}, false
5651}
5752
58- // increment returns the recorded increment for the given key, or false if absent.
59- func (m * recordingMetrics ) increment (key string ) (recordedMetric , bool ) {
60- m .mu .Lock ()
61- defer m .mu .Unlock ()
62- for _ , c := range m .increments {
63- if c .key == key {
64- return c , true
65- }
66- }
67- return recordedMetric {}, false
68- }
69-
7053// depsWithRecordingMetrics returns BaseDeps wired with a recording metrics sink
7154// plus the sink for assertions.
7255func depsWithRecordingMetrics (t * testing.T , base BaseDeps ) (BaseDeps , * recordingMetrics ) {
@@ -78,46 +61,23 @@ func depsWithRecordingMetrics(t *testing.T, base BaseDeps) (BaseDeps, *recording
7861 return base , rec
7962}
8063
81- func Test_recordFieldsUsage_Filtered (t * testing.T ) {
64+ func Test_recordFieldsFullBytes (t * testing.T ) {
8265 deps , rec := depsWithRecordingMetrics (t , BaseDeps {})
8366
84- recordFieldsUsage (context .Background (), deps , "search_code" , true , 100 , 30 )
85-
86- call , ok := rec .increment (metricFieldsToolCall )
87- require .True (t , ok )
88- assert .Equal (t , "search_code" , call .tags ["tool" ])
89- assert .Equal (t , "true" , call .tags ["filtered" ])
67+ recordFieldsFullBytes (context .Background (), deps , "search_code" , 100 )
9068
9169 full , ok := rec .counter (metricFieldsBytesFull )
9270 require .True (t , ok )
9371 assert .Equal (t , int64 (100 ), full .value )
9472 assert .Equal (t , "search_code" , full .tags ["tool" ])
73+ // The only tag is `tool`; adoption and filtered/unfiltered distinctions are
74+ // emitted by the hosted request middleware, not here.
9575 assert .NotContains (t , full .tags , "filtered" )
96-
97- sent , ok := rec .counter (metricFieldsBytesSent )
98- require .True (t , ok )
99- assert .Equal (t , int64 (30 ), sent .value )
100- }
101-
102- func Test_recordFieldsUsage_NotFiltered (t * testing.T ) {
103- deps , rec := depsWithRecordingMetrics (t , BaseDeps {})
104-
105- recordFieldsUsage (context .Background (), deps , "search_code" , false , 100 , 100 )
106-
107- call , ok := rec .increment (metricFieldsToolCall )
108- require .True (t , ok )
109- assert .Equal (t , "false" , call .tags ["filtered" ])
110-
111- // No byte counters are emitted when the response was not filtered.
112- _ , ok = rec .counter (metricFieldsBytesFull )
113- assert .False (t , ok )
114- _ , ok = rec .counter (metricFieldsBytesSent )
115- assert .False (t , ok )
11676}
11777
118- func Test_recordFieldsUsage_NilExporterDoesNotPanic (t * testing.T ) {
78+ func Test_recordFieldsFullBytes_NilExporterDoesNotPanic (t * testing.T ) {
11979 // BaseDeps with no Obsv falls back to a noop sink rather than panicking.
12080 assert .NotPanics (t , func () {
121- recordFieldsUsage (context .Background (), BaseDeps {}, "search_code" , true , 100 , 30 )
81+ recordFieldsFullBytes (context .Background (), BaseDeps {}, "search_code" , 100 )
12282 })
12383}
0 commit comments