Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: roll out ASN metrics to all servers #1585

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/shadowbox/model/shadowsocks_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ export interface ShadowsocksAccessKey {
}

export interface ShadowsocksServer {
// Annotates the Prometheus data metrics with ASN.
enableAsnMetrics(enable: boolean);

// Updates the server to accept only the given access keys.
update(keys: ShadowsocksAccessKey[]): Promise<void>;
}
23 changes: 0 additions & 23 deletions src/shadowbox/server/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -457,29 +457,6 @@ paths:
description: Setting successful
'400':
description: Invalid request
/experimental/asn-metrics/enabled:
put:
description: Annotates Prometheus data metrics with autonomous system numbers (ASN).
tags:
- Server
- Experimental
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
asnMetricsEnabled:
type: boolean
examples:
'0':
value: '{"asnMetricsEnabled": true}'
responses:
'204':
description: Setting successful
'400':
description: Invalid request
/experimental/access-key-data-limit:
put:
deprecated: true
Expand Down
3 changes: 0 additions & 3 deletions src/shadowbox/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ async function main() {
}
if (fs.existsSync(MMDB_LOCATION_ASN)) {
shadowsocksServer.configureAsnMetrics(MMDB_LOCATION_ASN);
if (serverConfig.data().experimental?.asnMetricsEnabled) {
shadowsocksServer.enableAsnMetrics(true);
}
}

const isReplayProtectionEnabled = createRolloutTracker(serverConfig).isRolloutEnabled(
Expand Down
41 changes: 0 additions & 41 deletions src/shadowbox/server/manager_service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1077,47 +1077,6 @@ describe('ShadowsocksManagerService', () => {
);
});
});
describe('enableAsnMetrics', () => {
it('Enables ASN metrics on the Shadowsocks Server', (done) => {
const serverConfig = new InMemoryConfig({} as ServerConfigJson);
const shadowsocksServer = new FakeShadowsocksServer();
spyOn(shadowsocksServer, 'enableAsnMetrics');
const service = new ShadowsocksManagerServiceBuilder()
.serverConfig(serverConfig)
.shadowsocksServer(shadowsocksServer)
.build();
service.enableAsnMetrics(
{params: {asnMetricsEnabled: true}},
{
send: (httpCode, _) => {
expect(httpCode).toEqual(204);
expect(shadowsocksServer.enableAsnMetrics).toHaveBeenCalledWith(true);
responseProcessed = true;
},
},
done
);
});
it('Sets value in the config', (done) => {
const serverConfig = new InMemoryConfig({} as ServerConfigJson);
const shadowsocksServer = new FakeShadowsocksServer();
const service = new ShadowsocksManagerServiceBuilder()
.serverConfig(serverConfig)
.shadowsocksServer(shadowsocksServer)
.build();
service.enableAsnMetrics(
{params: {asnMetricsEnabled: true}},
{
send: (httpCode, _) => {
expect(httpCode).toEqual(204);
expect(serverConfig.mostRecentWrite.experimental.asnMetricsEnabled).toBeTrue();
responseProcessed = true;
},
},
done
);
});
});
});

describe('bindService', () => {
Expand Down
38 changes: 0 additions & 38 deletions src/shadowbox/server/manager_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,6 @@ export function bindService(

// Experimental APIs.

apiServer.put(
`${apiPrefix}/experimental/asn-metrics/enabled`,
service.enableAsnMetrics.bind(service)
);

// Redirect former experimental APIs
apiServer.put(
`${apiPrefix}/experimental/access-key-data-limit`,
Expand Down Expand Up @@ -638,37 +633,4 @@ export class ShadowsocksManagerService {
res.send(HttpSuccess.NO_CONTENT);
next();
}

enableAsnMetrics(req: RequestType, res: ResponseType, next: restify.Next): void {
try {
logging.debug(`enableAsnMetrics request ${JSON.stringify(req.params)}`);
const asnMetricsEnabled = req.params.asnMetricsEnabled;
if (asnMetricsEnabled === undefined || asnMetricsEnabled === null) {
return next(
new restifyErrors.MissingParameterError(
{statusCode: 400},
'Parameter `asnMetricsEnabled` is missing'
)
);
} else if (typeof asnMetricsEnabled !== 'boolean') {
return next(
new restifyErrors.InvalidArgumentError(
{statusCode: 400},
'Parameter `asnMetricsEnabled` must be a boolean'
)
);
}
this.shadowsocksServer.enableAsnMetrics(asnMetricsEnabled);
if (this.serverConfig.data().experimental === undefined) {
this.serverConfig.data().experimental = {};
}
this.serverConfig.data().experimental.asnMetricsEnabled = asnMetricsEnabled;
this.serverConfig.write();
res.send(HttpSuccess.NO_CONTENT);
return next();
} catch (error) {
logging.error(error);
return next(new restifyErrors.InternalServerError());
}
}
}
2 changes: 0 additions & 2 deletions src/shadowbox/server/mocks/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export class InMemoryFile implements TextFile {
export class FakeShadowsocksServer implements ShadowsocksServer {
private accessKeys: ShadowsocksAccessKey[] = [];

enableAsnMetrics(_: boolean) {}

update(keys: ShadowsocksAccessKey[]) {
this.accessKeys = keys;
return Promise.resolve();
Expand Down
14 changes: 1 addition & 13 deletions src/shadowbox/server/outline_shadowsocks_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@ export class OutlineShadowsocksServer implements ShadowsocksServer {
return this;
}

/** Annotates the Prometheus data metrics with ASN. */
enableAsnMetrics(enable: boolean) {
if (enable && !this.ipAsnFilename) {
throw new Error('Cannot enable ASN metrics: no ASN database filename set');
}
const valueChanged = this.isAsnMetricsEnabled != enable;
this.isAsnMetricsEnabled = enable;
if (valueChanged && this.ssProcess) {
this.ssProcess.kill('SIGTERM');
}
}

enableReplayProtection(): OutlineShadowsocksServer {
this.isReplayProtectionEnabled = true;
return this;
Expand Down Expand Up @@ -121,7 +109,7 @@ export class OutlineShadowsocksServer implements ShadowsocksServer {
if (this.ipCountryFilename) {
commandArguments.push('-ip_country_db', this.ipCountryFilename);
}
if (this.isAsnMetricsEnabled && this.ipAsnFilename) {
if (this.ipAsnFilename) {
commandArguments.push('-ip_asn_db', this.ipAsnFilename);
}
if (this.verbose) {
Expand Down
2 changes: 1 addition & 1 deletion src/shadowbox/server/server_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface ServerConfigJson {
// Experimental configuration options that are expected to be short-lived.
experimental?: {
// Whether ASN metric annotation for Prometheus is enabled.
asnMetricsEnabled?: boolean;
asnMetricsEnabled?: boolean; // DEPRECATED
};
}

Expand Down
Loading