time_window

This commit is contained in:
Daniel LaCosse 2024-09-19 15:59:28 -04:00
parent 9b398a9a57
commit a0fc6bde60
3 changed files with 10 additions and 4 deletions

View file

@ -35,7 +35,7 @@ describe('PrometheusManagerMetrics', () => {
const managerMetrics = new PrometheusManagerMetrics(
new FakeTunnelTimePrometheusClient({US: 1000, CA: 2000})
);
const tunnelTime = await managerMetrics.getTunnelTimeByLocation({seconds: 0});
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}},

View file

@ -18,7 +18,9 @@ import {DataUsageByUser, DataUsageTimeframe} from '../model/metrics';
export type TunnelTimeDimension = 'access_key' | 'country' | 'asn';
interface TunnelTimeRequest {
seconds: number;
time_window: {
seconds: number;
};
}
interface TunnelTimeResponse {
@ -57,7 +59,9 @@ export class PrometheusManagerMetrics implements ManagerMetrics {
return {bytesTransferredByUserId: usage};
}
async getTunnelTimeByLocation({seconds}: TunnelTimeRequest): Promise<TunnelTimeResponse[]> {
async getTunnelTimeByLocation({
time_window: {seconds},
}: TunnelTimeRequest): Promise<TunnelTimeResponse[]> {
const {result} = await this.prometheusClient.query(
`sum(increase(shadowsocks_tunnel_time_seconds_per_location[${seconds}s])) by (location, asn, asorg)`
);

View file

@ -605,7 +605,9 @@ export class ShadowsocksManagerService {
try {
logging.debug(`getTunnelTime request ${JSON.stringify(req.params)}`);
const response = await this.managerMetrics.getTunnelTimeByLocation({
seconds: 30 * 24 * 60 * 60,
time_window: {
seconds: 30 * 24 * 60 * 60,
},
});
res.send(HttpSuccess.OK, response);
logging.debug(`getTunnelTime response ${JSON.stringify(response)}`);