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

Metrics #480

Merged
merged 50 commits into from
Jun 13, 2019
Merged

Metrics #480

merged 50 commits into from
Jun 13, 2019

Conversation

Half-Shot
Copy link
Contributor

This PR enables metrics support for the bridge. The way we are doing this is slightly weird. Rather than passing around a metrics instance to all of the handlers, I've just made a MetricPeg static class, which will host a IBridgeMetrics instance of your choosing. Personally, this feels more elegant.

@Half-Shot Half-Shot mentioned this pull request May 22, 2019
Copy link
Collaborator

@Sorunome Sorunome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soru is a bit confused, are these metrics only in-memory? are they saved somehow? if yes, how? If it is just a json blob file thingy like old user and room store, wouldn't that introduce a significant bottleneck?

// tslint:disable-next-line:only-arrow-functions
channel.send = function() {
MetricPeg.get.remoteCall("channel.send");
return channel.send.apply(channel, arguments);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this recurse? What if we call bindMetricsToChannel twice on a channel object, won't it do the metrics twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes hello I'm dumb, I wonder how we do this sanely.

@@ -389,6 +392,7 @@ export class DiscordBot {
}
const channel = guild.channels.get(room);
if (channel && channel.type === "text") {
this.ClientFactory.bindMetricsToChannel(channel as Discord.TextChannel);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we always bind the channel on message processing? Or even better, right when the message enters via the event listeners?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, because we only call the send function when sending stuff that came via matrix. Though I guess we should also bind in the event listeners too.

src/bot.ts Outdated
@@ -766,14 +776,13 @@ export class DiscordBot {
let rooms;
try {
rooms = await this.channelSync.GetRoomIdsFromChannel(msg.channel);
if (rooms === null) { throw Error(); }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new lines for if-condition due to {}?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I was being lazy, sorry.

private matrixRequest: Histogram;
private requestsInFlight: Map<string, number>;
private bridgeGauges: IBridgeGauges = {
matrixGhosts: 0,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these autofilled somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, by the bridge lib. Though some of them will remain 0

@Half-Shot
Copy link
Contributor Author

Soru is a bit confused, are these metrics only in-memory? are they saved somehow? if yes, how? If it is just a json blob file thingy like old user and room store, wouldn't that introduce a significant bottleneck?

By default it blackholes the metrics unless you enable prometheus in the config. If enabled, the bridge will simply add another endpoint onto the bridge's http listener which will spit out a line seperated list of values which are kept in memory. A prometheus instance will then poll this endpoint every X seconds. It's not at all memory intensive since reads are done asyncronously and writes are just updating integer values.

@Sorunome
Copy link
Collaborator

Soru is a bit confused, are these metrics only in-memory? are they saved somehow? if yes, how? If it is just a json blob file thingy like old user and room store, wouldn't that introduce a significant bottleneck?

By default it blackholes the metrics unless you enable prometheus in the config. If enabled, the bridge will simply add another endpoint onto the bridge's http listener which will spit out a line seperated list of values which are kept in memory. A prometheus instance will then poll this endpoint every X seconds. It's not at all memory intensive since reads are done asyncronously and writes are just updating integer values.

ah, so you need to run another program (prometheus server) to read out the metrics? makes sense, then

@Sorunome
Copy link
Collaborator

Sorunome commented Jun 4, 2019

why don't we bind this.clientFactory.bindMetricsToChannel(msg.channel as Discord.TextChannel); at the start of all those discord event listeners? (like edit, delete etc)

Sorunome and others added 8 commits June 4, 2019 19:30
Signed-off-by: pacien <pacien.trangirard@pacien.net>
Signed-off-by: pacien <pacien.trangirard@pacien.net>
Signed-off-by: pacien <pacien.trangirard@pacien.net>
github: closes #487

Signed-off-by: pacien <pacien.trangirard@pacien.net>
fixing compilation with Typescript 3.5.1

github: closes #487

Signed-off-by: pacien <pacien.trangirard@pacien.net>
Fix compilation failure with TS 3.5.1
Override config with environment variables
@Half-Shot Half-Shot requested a review from Sorunome June 13, 2019 10:50
@Half-Shot
Copy link
Contributor Author

💥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants