mirror of
https://github.com/OutlineFoundation/outline-server.git
synced 2026-08-28 12:21:11 +00:00
asn example, remove rounding
This commit is contained in:
parent
a0fc6bde60
commit
45128215ae
3 changed files with 16 additions and 10 deletions
|
|
@ -33,12 +33,13 @@ describe('PrometheusManagerMetrics', () => {
|
|||
|
||||
it('getTunnelTimeByLocation', async (done) => {
|
||||
const managerMetrics = new PrometheusManagerMetrics(
|
||||
new FakeTunnelTimePrometheusClient({US: 1000, CA: 2000})
|
||||
new FakeTunnelTimePrometheusClient({US: {1: 1000, 2: 1000}, CA: {3: 2000}})
|
||||
);
|
||||
const tunnelTime = await managerMetrics.getTunnelTimeByLocation({time_window: {seconds: 0}});
|
||||
expect(tunnelTime).toEqual([
|
||||
{location: 'US', asn: undefined, as_org: undefined, tunnel_time: {seconds: 1000}},
|
||||
{location: 'CA', asn: undefined, as_org: undefined, tunnel_time: {seconds: 2000}},
|
||||
{location: 'US', asn: 1, as_org: undefined, tunnel_time: {seconds: 1000}},
|
||||
{location: 'US', asn: 2, as_org: undefined, tunnel_time: {seconds: 1000}},
|
||||
{location: 'CA', asn: 3, as_org: undefined, tunnel_time: {seconds: 2000}},
|
||||
]);
|
||||
done();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ export class PrometheusManagerMetrics implements ManagerMetrics {
|
|||
asn: entry.metric['asn'] !== undefined ? parseInt(entry.metric['asn'], 10) : undefined,
|
||||
as_org: entry.metric['asorg'],
|
||||
tunnel_time: {
|
||||
seconds: Math.round(parseFloat(entry.value[1])),
|
||||
seconds: parseFloat(entry.value[1]),
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,18 +67,23 @@ export class FakeDataBytesTransferredPrometheusClient extends PrometheusClient {
|
|||
}
|
||||
|
||||
export class FakeTunnelTimePrometheusClient extends PrometheusClient {
|
||||
constructor(public tunnelTimeByLocation: {[location: string]: number}) {
|
||||
constructor(public tunnelTimeByLocation: {[location: string]: {[as: number]: number}}) {
|
||||
super('');
|
||||
}
|
||||
|
||||
async query(_query: string): Promise<QueryResultData> {
|
||||
const queryResultData = {result: []} as QueryResultData;
|
||||
for (const location of Object.keys(this.tunnelTimeByLocation)) {
|
||||
const tunnelTime = this.tunnelTimeByLocation[location] || 0;
|
||||
queryResultData.result.push({
|
||||
metric: {location},
|
||||
value: [tunnelTime, `${tunnelTime}`],
|
||||
});
|
||||
const tunnelTimeByAsn = this.tunnelTimeByLocation[location] || {};
|
||||
|
||||
for (const asn of Object.keys(tunnelTimeByAsn)) {
|
||||
const tunnelTime = tunnelTimeByAsn[asn] || 0;
|
||||
|
||||
queryResultData.result.push({
|
||||
metric: {location, asn},
|
||||
value: [tunnelTime, `${tunnelTime}`],
|
||||
});
|
||||
}
|
||||
}
|
||||
return queryResultData;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue