MCPcopy Index your code
hub / github.com/coder/coder / RecordCompaction

Method RecordCompaction

coderd/x/chatd/chatloop/metrics.go:123–140  ·  view source on GitHub ↗

RecordCompaction classifies and records a compaction attempt. It is a no-op when m is nil.

(provider, model string, compacted bool, err error)

Source from the content-addressed store, hash-verified

121// RecordCompaction classifies and records a compaction attempt.
122// It is a no-op when m is nil.
123func (m *Metrics) RecordCompaction(provider, model string, compacted bool, err error) {
124 if m == nil {
125 return
126 }
127 switch {
128 case err != nil && errors.Is(err, context.DeadlineExceeded):
129 m.CompactionTotal.WithLabelValues(provider, model, CompactionResultTimeout).Inc()
130 case err != nil && errors.Is(err, context.Canceled):
131 // User interruption, not a compaction failure.
132 return
133 case err != nil:
134 m.CompactionTotal.WithLabelValues(provider, model, CompactionResultError).Inc()
135 case compacted:
136 m.CompactionTotal.WithLabelValues(provider, model, CompactionResultSuccess).Inc()
137 // !compacted && err == nil means threshold not reached -- not
138 // recorded.
139 }
140}
141
142// RecordStreamRetry increments stream_retries_total. The caller
143// must obtain classified via chaterror.Classify (non-empty Kind).

Callers 3

TestRecordCompactionFunction · 0.95
RunFunction · 0.80
tryCompactOnExitFunction · 0.80

Calls 2

WithLabelValuesMethod · 0.80
IsMethod · 0.45

Tested by 1

TestRecordCompactionFunction · 0.76