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

Enhance stats #17

Closed
2 of 4 tasks
MarcoBuster opened this issue Nov 25, 2020 · 8 comments · Fixed by #22 or #24
Closed
2 of 4 tasks

Enhance stats #17

MarcoBuster opened this issue Nov 25, 2020 · 8 comments · Fixed by #22 or #24
Labels
enhancement New feature or request

Comments

@MarcoBuster
Copy link
Collaborator

MarcoBuster commented Nov 25, 2020

Statistics can be helpful in many ways such as monitoring the instance and implement load balancers.

  • Currently, the stats format is easy to read for an human but hard to parse for a script so we need to add an option to retrieve them as JSON (with backwards compatibility).
  • @andrew-ld suggests to implement a public method to read (own) bot statistics from the public endpoint, like this: https://botapi.example.org/botID:TOKEN/getStats with a command line option or environment option to enable/disable it.

Progress tracker

  • JSON format
  • Toggle to hide sensible data
  • Per-bot public statistics
  • Documentation
@MarcoBuster MarcoBuster added the enhancement New feature or request label Nov 25, 2020
@MarcoBuster MarcoBuster added this to To do in TDLight bot api via automation Nov 25, 2020
@luckydonald
Copy link
Collaborator

I'm currently working on 1, albeit using the usual JsonBuilder to get the stats.
That way we can easily extract and re-use that for any bot method.

I'm also adding a toggle to hide the sensible data (bot token so far) from it, so it can be served public (json or not).

@luckydonald
Copy link
Collaborator

image

@luckydonald
Copy link
Collaborator

Hmmm, I'm stuck with the bots.

It starts at

for (auto top_bot_id : top_bot_ids) {
auto *client_info = clients_.get(top_bot_id.second);
CHECK(client_info);
auto bot_info = client_info->client_->get_actor_unsafe()->get_bot_info();
sb << "\n";
sb << "id\t" << bot_info.id_ << "\n";

goes through all the bots connected (which could be a very long list)
and writes as many as possible to the buffer, until that buffer is full:
if (sb.is_error()) {
break;
}
}

However I haven't find a way to really mimic that with how the Json works.

@luckydonald
Copy link
Collaborator

I can probably have that write to the buffer as well, similar to how the text does it,
but in case of that overflow we would end up without the closing tags (]}) which is rather suboptimal.

I would say for a first implementation that probably wouldn't be an issue for most, as most of those self hosted instances will run with only a few bots, and if it get's too long you'll just have to fall back to the the non-json version for now.

@MarcoBuster
Copy link
Collaborator Author

Awesome work, thank you. Keep us updated!

@MarcoBuster MarcoBuster moved this from To do to In progress in TDLight bot api Dec 11, 2020
@luckydonald
Copy link
Collaborator

Well I'm less in control of that buffer than I thought I would be when using the regular json stuff.
I think I will reduce the "bots" array to just a list of id's which then could be queried independently, over the normal api or something

@luckydonald
Copy link
Collaborator

While add it I also added a CLI flag to disable the display of sensible data (bot tokens + Webhook urls), which enables the stats to be hosted public.

@luckydonald
Copy link
Collaborator

If someone already wants to give it a try, 374928c seems to be a working one.
There are still a few fields missing.
Regarding the buffer size problem, I now show only the internal id + the ranking if it's more than 100 active bots.

This was linked to pull requests Dec 11, 2020
TDLight bot api automation moved this from In progress to Done Dec 15, 2020
MarcoBuster pushed a commit that referenced this issue Jan 24, 2021
The work regarding #17.

With 374928c we could merge a working version where the json is still missing a few fields, to iterate from there.

It is available via the normal stats endpoint by calling /json as the path.
Everything else will have the old text style.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
2 participants