diff --git a/src/shadowbox/model/access_key.ts b/src/shadowbox/model/access_key.ts index 83c30ae92..88f6e58e0 100644 --- a/src/shadowbox/model/access_key.ts +++ b/src/shadowbox/model/access_key.ts @@ -13,7 +13,6 @@ // limitations under the License. export type AccessKeyId = string; -export type AccessKeyMetricsId = string; // Parameters needed to access a Shadowsocks proxy. export interface ProxyParams { @@ -38,8 +37,6 @@ export interface AccessKey { readonly id: AccessKeyId; // Admin-controlled, editable name for this access key. readonly name: string; - // Used in metrics reporting to decouple from the real id. Can change. - readonly metricsId: AccessKeyMetricsId; // Parameters to access the proxy readonly proxyParams: ProxyParams; // Whether the access key has exceeded the data transfer limit. @@ -78,8 +75,6 @@ export interface AccessKeyRepository { setHostname(hostname: string): void; // Apply the specified update to the specified access key. Throws on failure. renameAccessKey(id: AccessKeyId, name: string): void; - // Gets the metrics id for a given Access Key. - getMetricsId(id: AccessKeyId): AccessKeyMetricsId | undefined; // Sets a data transfer limit for all access keys. setDefaultDataLimit(limit: DataLimit): void; // Removes the access key data transfer limit. diff --git a/src/shadowbox/server/main.ts b/src/shadowbox/server/main.ts index fe8dbcb53..675752b8b 100644 --- a/src/shadowbox/server/main.ts +++ b/src/shadowbox/server/main.ts @@ -26,7 +26,6 @@ import * as json_config from '../infrastructure/json_config'; import * as logging from '../infrastructure/logging'; import {PrometheusClient, startPrometheus} from '../infrastructure/prometheus_scraper'; import {RolloutTracker} from '../infrastructure/rollout'; -import {AccessKeyId} from '../model/access_key'; import * as version from './version'; import {PrometheusManagerMetrics} from './manager_metrics'; @@ -216,13 +215,6 @@ async function main() { ); const metricsReader = new PrometheusUsageMetrics(prometheusClient); - const toMetricsId = (id: AccessKeyId) => { - try { - return accessKeyRepository.getMetricsId(id); - } catch (e) { - logging.warn(`Failed to get metrics id for access key ${id}: ${e}`); - } - }; const managerMetrics = new PrometheusManagerMetrics(prometheusClient); const metricsCollector = new RestMetricsCollectorClient(metricsCollectorUrl); const metricsPublisher: SharedMetricsPublisher = new OutlineSharedMetricsPublisher( @@ -230,7 +222,6 @@ async function main() { serverConfig, accessKeyConfig, metricsReader, - toMetricsId, metricsCollector ); const managerService = new ShadowsocksManagerService( diff --git a/src/shadowbox/server/server_access_key.ts b/src/shadowbox/server/server_access_key.ts index 3f513948e..a71a494aa 100644 --- a/src/shadowbox/server/server_access_key.ts +++ b/src/shadowbox/server/server_access_key.ts @@ -13,7 +13,6 @@ // limitations under the License. import * as randomstring from 'randomstring'; -import * as uuidv4 from 'uuid/v4'; import {Clock} from '../infrastructure/clock'; import {isPortUsed} from '../infrastructure/get_port'; @@ -24,7 +23,6 @@ import { AccessKey, AccessKeyCreateParams, AccessKeyId, - AccessKeyMetricsId, AccessKeyRepository, DataLimit, ProxyParams, @@ -36,7 +34,6 @@ import {PrometheusManagerMetrics} from './manager_metrics'; // The format as json of access keys in the config file. interface AccessKeyStorageJson { id: AccessKeyId; - metricsId: AccessKeyId; name: string; password: string; port: number; @@ -57,7 +54,6 @@ class ServerAccessKey implements AccessKey { constructor( readonly id: AccessKeyId, public name: string, - public metricsId: AccessKeyMetricsId, readonly proxyParams: ProxyParams, public dataLimit?: DataLimit ) {} @@ -79,7 +75,6 @@ function makeAccessKey(hostname: string, accessKeyJson: AccessKeyStorageJson): A return new ServerAccessKey( accessKeyJson.id, accessKeyJson.name, - accessKeyJson.metricsId, proxyParams, accessKeyJson.dataLimit ); @@ -88,7 +83,6 @@ function makeAccessKey(hostname: string, accessKeyJson: AccessKeyStorageJson): A function accessKeyToStorageJson(accessKey: AccessKey): AccessKeyStorageJson { return { id: accessKey.id, - metricsId: accessKey.metricsId, name: accessKey.name, password: accessKey.proxyParams.password, port: accessKey.proxyParams.portNumber, @@ -213,7 +207,6 @@ export class ServerAccessKeyRepository implements AccessKeyRepository { throw new errors.PasswordConflict(id); } - const metricsId = uuidv4(); const password = params?.password ?? generatePassword(); const encryptionMethod = params?.encryptionMethod || this.NEW_USER_ENCRYPTION_METHOD; @@ -241,7 +234,7 @@ export class ServerAccessKeyRepository implements AccessKeyRepository { }; const name = params?.name ?? ''; const dataLimit = params?.dataLimit; - const accessKey = new ServerAccessKey(id, name, metricsId, proxyParams, dataLimit); + const accessKey = new ServerAccessKey(id, name, proxyParams, dataLimit); this.accessKeys.push(accessKey); this.saveAccessKeys(); await this.updateServer(); @@ -306,11 +299,6 @@ export class ServerAccessKeyRepository implements AccessKeyRepository { this.enforceAccessKeyDataLimits(); } - getMetricsId(id: AccessKeyId): AccessKeyMetricsId | undefined { - const accessKey = this.getAccessKey(id); - return accessKey ? accessKey.metricsId : undefined; - } - // Compares access key usage with collected metrics, marking them as under or over limit. // Updates access key data usage. async enforceAccessKeyDataLimits() { diff --git a/src/shadowbox/server/shared_metrics.spec.ts b/src/shadowbox/server/shared_metrics.spec.ts index 3866eeed2..2d07ea4e9 100644 --- a/src/shadowbox/server/shared_metrics.spec.ts +++ b/src/shadowbox/server/shared_metrics.spec.ts @@ -14,7 +14,7 @@ import {ManualClock} from '../infrastructure/clock'; import {InMemoryConfig} from '../infrastructure/json_config'; -import {AccessKeyId, DataLimit} from '../model/access_key'; +import {DataLimit} from '../model/access_key'; import * as version from './version'; import {AccessKeyConfigJson} from './server_access_key'; @@ -38,7 +38,6 @@ describe('OutlineSharedMetricsPublisher', () => { serverConfig, null, null, - null, null ); expect(publisher.isSharingEnabled()).toBeFalsy(); @@ -58,7 +57,6 @@ describe('OutlineSharedMetricsPublisher', () => { serverConfig, null, null, - null, null ); expect(publisher.isSharingEnabled()).toBeTruthy(); @@ -70,14 +68,12 @@ describe('OutlineSharedMetricsPublisher', () => { let startTime = clock.nowMs; const serverConfig = new InMemoryConfig({serverId: 'server-id'}); const usageMetrics = new ManualUsageMetrics(); - const toMetricsId = (id: AccessKeyId) => `M(${id})`; const metricsCollector = new FakeMetricsCollector(); const publisher = new OutlineSharedMetricsPublisher( clock, serverConfig, null, usageMetrics, - toMetricsId, metricsCollector ); @@ -130,14 +126,12 @@ describe('OutlineSharedMetricsPublisher', () => { const startTime = clock.nowMs; const serverConfig = new InMemoryConfig({serverId: 'server-id'}); const usageMetrics = new ManualUsageMetrics(); - const toMetricsId = (id: AccessKeyId) => `M(${id})`; const metricsCollector = new FakeMetricsCollector(); const publisher = new OutlineSharedMetricsPublisher( clock, serverConfig, null, usageMetrics, - toMetricsId, metricsCollector ); @@ -177,7 +171,6 @@ describe('OutlineSharedMetricsPublisher', () => { const makeKeyJson = (dataLimit?: DataLimit) => { return { id: (keyId++).toString(), - metricsId: 'id', name: 'name', password: 'pass', port: 12345, @@ -193,7 +186,6 @@ describe('OutlineSharedMetricsPublisher', () => { serverConfig, keyConfig, new ManualUsageMetrics(), - (_id: AccessKeyId) => '', metricsCollector ); @@ -242,7 +234,6 @@ describe('OutlineSharedMetricsPublisher', () => { serverConfig, new InMemoryConfig({}), new ManualUsageMetrics(), - (_id: AccessKeyId) => '', metricsCollector ); diff --git a/src/shadowbox/server/shared_metrics.ts b/src/shadowbox/server/shared_metrics.ts index 764554712..f1ab67a3a 100644 --- a/src/shadowbox/server/shared_metrics.ts +++ b/src/shadowbox/server/shared_metrics.ts @@ -17,7 +17,6 @@ import * as follow_redirects from '../infrastructure/follow_redirects'; import {JsonConfig} from '../infrastructure/json_config'; import * as logging from '../infrastructure/logging'; import {PrometheusClient} from '../infrastructure/prometheus_scraper'; -import {AccessKeyId, AccessKeyMetricsId} from '../model/access_key'; import * as version from './version'; import {AccessKeyConfigJson} from './server_access_key'; @@ -148,14 +147,12 @@ export class OutlineSharedMetricsPublisher implements SharedMetricsPublisher { // serverConfig: where the enabled/disable setting is persisted // keyConfig: where access keys are persisted // usageMetrics: where we get the metrics from - // toMetricsId: maps Access key ids to metric ids // metricsUrl: where to post the metrics constructor( private clock: Clock, private serverConfig: JsonConfig, private keyConfig: JsonConfig, usageMetrics: UsageMetrics, - private toMetricsId: (accessKeyId: AccessKeyId) => AccessKeyMetricsId, private metricsCollector: MetricsCollectorClient ) { // Start timer