Skip to content

Commit

Permalink
ok, empty state works
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellacosse committed Nov 11, 2024
1 parent 568cb7c commit e06ab96
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/shadowbox/server/manager_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ export class PrometheusManagerMetrics implements ManagerMetrics {
asn: parseInt(entry.metric['asn']),
asOrg: entry.metric['asorg'],
tunnelTime: {
seconds: tunnelTimeByLocation.result.find((entry) => {
seconds: tunnelTimeByLocation.result.find((target) => {
return (
entry.metric['location'] === entry.metric['location'] &&
entry.metric['asn'] === entry.metric['asn'] &&
entry.metric['asorg'] === entry.metric['asorg']
entry.metric['location'] === target.metric['location'] &&
entry.metric['asn'] === target.metric['asn'] &&
entry.metric['asorg'] === target.metric['asorg']
);
}),
},
Expand All @@ -109,8 +109,8 @@ export class PrometheusManagerMetrics implements ManagerMetrics {
accessKeys.push({
accessKeyId: parseInt(entry.metric['access_key']),
tunnelTime: {
seconds: tunnelTimeByAccessKey.result.find((entry) => {
return entry.metric['access_key'] === entry.metric['access_key'];
seconds: tunnelTimeByAccessKey.result.find((target) => {
return entry.metric['access_key'] === target.metric['access_key'];
}),
},
dataTransferred: {
Expand Down
13 changes: 10 additions & 3 deletions src/shadowbox/server/manager_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,18 +613,25 @@ export class ShadowsocksManagerService {
logging.debug(`getServerMetrics request ${JSON.stringify(req.params)}`);

if (!req.query?.since) {
throw new TypeError("Missing 'since' parameter. Must be an ISO timestamp");
return next(
new restifyErrors.MissingParameterError({statusCode: 400}, 'Parameter `since` is missing')
);
}

const timestamp = new Date(req.query.since as string);
const isIsoTimestamp =
!isNaN(timestamp.getTime()) && timestamp.toISOString() === req.query.since;

if (!isIsoTimestamp) {
throw new TypeError(`'since' parameter must be an ISO timestamp. Got ${req.query.since}`);
return next(
new restifyErrors.InvalidArgumentError(
{statusCode: 400},
`'since' parameter must be an ISO timestamp. Got ${req.query.since}`
)
);
}

const hours = Math.floor(new Date().getTime() - timestamp.getTime() / (1000 * 60 * 60));
const hours = Math.floor((new Date().getTime() - timestamp.getTime()) / (1000 * 60 * 60));

const response = await this.managerMetrics.getServerMetrics({hours});
res.send(HttpSuccess.OK, response);
Expand Down

0 comments on commit e06ab96

Please sign in to comment.