-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
electron: allow accessing the metrics endpoint for performance analysis
By default, when running Theia in Electron, all endpoints are protected by the ElectronTokenValidator. This patch allows accessing the '/metrics' endpoint without a token, which enables us to collect metrics for performance analysis. For this, ElectronTokenValidator is extended to allow access to the metrics endpoint. All other endpoints are still protected. Contributed on behalf of STMicroelectronics Signed-off-by: Olaf Lessenich <[email protected]>
- Loading branch information
Showing
4 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/metrics/src/electron-node/electron-metrics-backend-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2023 STMicroelectronics and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
|
||
import { ContainerModule } from '@theia/core/shared/inversify'; | ||
import { MetricsElectronTokenValidator } from './electron-token-validator'; | ||
import { ElectronTokenValidator } from '@theia/core/lib/electron-node/token/electron-token-validator'; | ||
import { BackendApplicationContribution } from '@theia/core/lib/node'; | ||
import { ExtensionMetricsContribution, MetricsBackendApplicationContribution, MetricsContribution, NodeMetricsContribution } from '../node'; | ||
import { ConnectionHandler, RpcConnectionHandler, bindContributionProvider } from '@theia/core'; | ||
import { measurementNotificationServicePath } from '../common'; | ||
import { MeasurementMetricsBackendContribution } from '../node/measurement-metrics-contribution'; | ||
|
||
export default new ContainerModule((bind, unbind, isBound, rebind) => { | ||
bind(MetricsElectronTokenValidator).toSelf().inSingletonScope(); | ||
rebind(ElectronTokenValidator).to(MetricsElectronTokenValidator); | ||
|
||
bindContributionProvider(bind, MetricsContribution); | ||
bind(MetricsContribution).to(NodeMetricsContribution).inSingletonScope(); | ||
bind(MetricsContribution).to(ExtensionMetricsContribution).inSingletonScope(); | ||
|
||
bind(MeasurementMetricsBackendContribution).toSelf().inSingletonScope(); | ||
bind(MetricsContribution).toService(MeasurementMetricsBackendContribution); | ||
bind(ConnectionHandler).toDynamicValue(ctx => | ||
new RpcConnectionHandler(measurementNotificationServicePath, | ||
() => ctx.container.get(MeasurementMetricsBackendContribution))); | ||
|
||
bind(BackendApplicationContribution).to(MetricsBackendApplicationContribution).inSingletonScope(); | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/metrics/src/electron-node/electron-token-validator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2023 STMicroelectronics and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
|
||
import * as http from 'http'; | ||
import { injectable, postConstruct } from '@theia/core/shared/inversify'; | ||
import { ElectronTokenValidator } from '@theia/core/lib/electron-node/token/electron-token-validator'; | ||
import { IncomingMessage } from 'http'; | ||
import { MetricsBackendApplicationContribution } from '../node/metrics-backend-application-contribution'; | ||
import { MaybePromise } from '@theia/core'; | ||
|
||
@injectable() | ||
export class MetricsElectronTokenValidator extends ElectronTokenValidator { | ||
@postConstruct() | ||
protected override init(): void { | ||
super.init(); | ||
} | ||
|
||
override allowWsUpgrade(request: http.IncomingMessage): MaybePromise<boolean> { | ||
return this.allowRequest(request); | ||
} | ||
|
||
override allowRequest(request: IncomingMessage): boolean { | ||
return request.url === MetricsBackendApplicationContribution.ENDPOINT || super.allowRequest(request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters