Skip to content

Commit a8da492

Browse files
committed
Introduce gitpod_server_topic_read_total counter metrics, which counts the amount of times that server reads messagebus topic for each workspace.
Signed-off-by: ArthurSens <[email protected]>
1 parent 92cdef0 commit a8da492

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

components/gitpod-messagebus/src/messagebus.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,11 @@ export abstract class AbstractTopicListener<T> implements MessagebusListener {
442442
constructor(protected readonly exchangeName: string, protected readonly listener: TopicListener<T>) { }
443443

444444
async establish(channel: Channel): Promise<void> {
445-
const topic = await this.topic();
445+
const topic = this.topic();
446446
return this.doEstablish(channel, topic);
447447
}
448448

449-
abstract topic(): Promise<string>;
449+
abstract topic(): string;
450450

451451
protected async doEstablish(channel: Channel, topic: string): Promise<void> {
452452
if (channel === undefined) {

components/server/src/consensus/rabbitmq-consensus-leader-messenger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class RabbitMQConsensusLeaderMessenger extends AbstractMessageBusIntegrat
9898

9999
class EventListener extends AbstractTopicListener<RaftMessage> {
100100

101-
async topic(): Promise<string> {
101+
topic(): string {
102102
return '';
103103
}
104104

components/server/src/prometheus-metrics.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,16 @@ const httpRequestDuration = new prometheusClient.Histogram({
8888
export function observeHttpRequestDuration(method: string, route: string, statusCode: number, durationInSeconds: number) {
8989
httpRequestDuration.observe({ method, route, statusCode }, durationInSeconds);
9090
}
91+
92+
const messagebusTopicReads = new prometheusClient.Counter({
93+
name: 'gitpod_server_topic_reads_total',
94+
help: 'The amount of reads from messagebus topics.',
95+
labelNames: ['topic'],
96+
registers: [prometheusClient.register]
97+
});
98+
99+
export function increaseMessagebusTopicReads(topic: string) {
100+
messagebusTopicReads.inc({
101+
topic,
102+
})
103+
}

components/server/src/workspace/messagebus-integration.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ import { Channel, Message } from "amqplib";
1313
import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing";
1414
import * as opentracing from "opentracing";
1515
import { CancellationTokenSource } from "vscode-ws-jsonrpc";
16+
import { increaseMessagebusTopicReads } from '../prometheus-metrics';
1617

1718
export class WorkspaceInstanceUpdateListener extends AbstractTopicListener<WorkspaceInstance> {
1819

1920
constructor(protected readonly messageBusHelper: MessageBusHelper, listener: TopicListener<WorkspaceInstance>, protected readonly userId?: string) {
2021
super(messageBusHelper.workspaceExchange, listener);
2122
}
2223

23-
async topic() {
24+
topic() {
2425
return this.messageBusHelper.getWsTopicForListening(this.userId, undefined, "updates");
2526
}
2627
}
@@ -31,7 +32,7 @@ export class HeadlessWorkspaceLogListener extends AbstractTopicListener<Headless
3132
super(messageBusHelper.workspaceExchange, listener);
3233
}
3334

34-
async topic() {
35+
topic() {
3536
return this.messageBusHelper.getWsTopicForListening(undefined, this.workspaceID, "headless-log");
3637
}
3738

@@ -117,6 +118,7 @@ export class MessageBusIntegration extends AbstractMessageBusIntegration {
117118
const listener = new HeadlessWorkspaceLogListener(this.messageBusHelper, callback, workspaceID);
118119
const cancellationTokenSource = new CancellationTokenSource()
119120
this.listen(listener, cancellationTokenSource.token);
121+
increaseMessagebusTopicReads(listener.topic())
120122
return Disposable.create(() => cancellationTokenSource.cancel())
121123
}
122124

@@ -131,6 +133,7 @@ export class MessageBusIntegration extends AbstractMessageBusIntegration {
131133
const listener = new WorkspaceInstanceUpdateListener(this.messageBusHelper, callback, userId);
132134
const cancellationTokenSource = new CancellationTokenSource()
133135
this.listen(listener, cancellationTokenSource.token);
136+
increaseMessagebusTopicReads(listener.topic())
134137
return Disposable.create(() => cancellationTokenSource.cancel())
135138
}
136139

components/ws-manager-bridge/src/messagebus-integration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class WorkspaceStatusUpdateListener extends AbstractTopicListener<WorkspaceStatu
104104
super(MessageBusIntegration.WORKSPACE_EXCHANGE, listener);
105105
}
106106

107-
async topic() {
107+
topic() {
108108
return this._topic;
109109
}
110110
}
@@ -115,7 +115,7 @@ class WorkspaceLogListener extends AbstractTopicListener<WorkspaceLogMessage.AsO
115115
super(MessageBusIntegration.WORKSPACE_EXCHANGE, listener);
116116
}
117117

118-
async topic() {
118+
topic() {
119119
return this._topic;
120120
}
121121
}

0 commit comments

Comments
 (0)