mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-06 17:37:47 +08:00
chore: update gateway pressure observability
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
findMetricSamples,
|
||||
findMetricValueNumber,
|
||||
parsePrometheusSamples,
|
||||
sumMetricValues,
|
||||
@@ -34,4 +35,15 @@ decision_remote_total{route_kind="responses",reason="remote_decision_miss"} 3
|
||||
|
||||
expect(sumMetricValues(samples, 'decision_remote_total')).toBe(5)
|
||||
})
|
||||
|
||||
it('finds all matching samples by full or suffix metric name', () => {
|
||||
const samples = parsePrometheusSamples(`
|
||||
aether_gateway_upstream_target_selected_total{target="openai"} 4
|
||||
aether_gateway_upstream_target_selected_total{target="azure"} 6
|
||||
aether_gateway_upstream_target_saturated_total{target="openai"} 1
|
||||
`)
|
||||
|
||||
expect(findMetricSamples(samples, 'upstream_target_selected_total')).toHaveLength(2)
|
||||
expect(sumMetricValues(samples, 'upstream_target_selected_total')).toBe(10)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -44,6 +44,13 @@ export function sumMetricValues(
|
||||
}, 0)
|
||||
}
|
||||
|
||||
export function findMetricSamples(
|
||||
samples: PrometheusSample[],
|
||||
metricName: string
|
||||
): PrometheusSample[] {
|
||||
return samples.filter(sample => metricNameMatches(sample.name, metricName))
|
||||
}
|
||||
|
||||
function metricNameMatches(actual: string, expected: string): boolean {
|
||||
return actual === expected || actual.split('_').pop() === expected || actual.endsWith(`_${expected}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user