From b38c42c5a968e3aa6baf491cdc8a1ffa3f2fb667 Mon Sep 17 00:00:00 2001 From: Szymon Uglis Date: Mon, 25 Sep 2023 18:30:11 +0200 Subject: [PATCH] Release 3.3.2 --- CHANGELOG.md | 5 + bin/running_on_dart.dart | 1 - docker-compose.prod.yml | 2 +- lib/running_on_dart.dart | 1 - lib/src/commands/docs.dart | 6 +- lib/src/commands/github.dart | 6 +- lib/src/commands/tag.dart | 6 +- lib/src/services/prometheus.dart | 206 ------------------------------- lib/src/settings.dart | 2 +- pubspec.yaml | 2 +- 10 files changed, 11 insertions(+), 226 deletions(-) delete mode 100644 lib/src/services/prometheus.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 7acbff4..f4aff3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.3.2 + +- Fix docs command +- Remove prometheus + ## 3.3.1 - Fix docs command diff --git a/bin/running_on_dart.dart b/bin/running_on_dart.dart index 11ac077..d1368f4 100644 --- a/bin/running_on_dart.dart +++ b/bin/running_on_dart.dart @@ -51,7 +51,6 @@ void main() async { PoopNameService.init(client); JoinLogsService.init(client); TagService.init(); - PrometheusService.init(client, commands); MusicService.init(client); // Connect diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index fef09d5..209b5eb 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -1,7 +1,7 @@ version: '3.9' services: running_on_dart: - image: ghcr.io/nyxx-discord/running_on_dart:3.3.1 + image: ghcr.io/nyxx-discord/running_on_dart:3.3.2 container_name: running_on_dart env_file: - .env diff --git a/lib/running_on_dart.dart b/lib/running_on_dart.dart index 1450c84..0c9f37d 100644 --- a/lib/running_on_dart.dart +++ b/lib/running_on_dart.dart @@ -18,7 +18,6 @@ export 'src/services/guild_settings.dart'; export 'src/services/join_logs.dart'; export 'src/services/music.dart'; export 'src/services/poop_name.dart'; -export 'src/services/prometheus.dart'; export 'src/services/reminder.dart'; export 'src/services/tag.dart'; export 'src/settings.dart'; diff --git a/lib/src/commands/docs.dart b/lib/src/commands/docs.dart index 2377eb8..2ab0698 100644 --- a/lib/src/commands/docs.dart +++ b/lib/src/commands/docs.dart @@ -6,13 +6,9 @@ import 'package:running_on_dart/running_on_dart.dart'; import 'package:running_on_dart/src/models/docs.dart'; import 'package:running_on_dart/src/util.dart'; -ChatCommand docs = ChatCommand( +final docs = ChatGroup( 'docs', 'Search and get documentation for various packages', - id( - 'docs', - (IChatContext context) => - context.respond(MessageBuilder.content(defaultDocsResponse.trim()))), children: [ ChatCommand( 'info', diff --git a/lib/src/commands/github.dart b/lib/src/commands/github.dart index 68c4440..e87e72d 100644 --- a/lib/src/commands/github.dart +++ b/lib/src/commands/github.dart @@ -7,13 +7,9 @@ import 'package:running_on_dart/src/models/github.dart'; import 'package:running_on_dart/src/services/github.dart'; import 'package:running_on_dart/src/util.dart'; -final github = ChatCommand( +final github = ChatGroup( 'github', 'Get information about nyxx on GitHub', - id( - 'github', - (MessageChatContext context) => context - .respond(MessageBuilder.content(defaultGithubResponse.trim()))), children: [ ChatCommand( 'info', diff --git a/lib/src/commands/tag.dart b/lib/src/commands/tag.dart index 9c1a0c2..46e3e7f 100644 --- a/lib/src/commands/tag.dart +++ b/lib/src/commands/tag.dart @@ -4,13 +4,9 @@ import 'package:running_on_dart/running_on_dart.dart'; import 'package:running_on_dart/src/models/tag.dart'; import 'package:running_on_dart/src/util.dart'; -ChatCommand tag = ChatCommand.textOnly( +final tag = ChatGroup( 'tag', 'Create and manage tags', - id( - 'tag', - (IChatContext context, Tag tag) => - context.respond(MessageBuilder.content(tag.content))), children: [ ChatCommand( 'create', diff --git a/lib/src/services/prometheus.dart b/lib/src/services/prometheus.dart deleted file mode 100644 index faa1062..0000000 --- a/lib/src/services/prometheus.dart +++ /dev/null @@ -1,206 +0,0 @@ -import 'dart:async'; -import 'dart:math'; - -import 'package:logging/logging.dart'; -import 'package:nyxx/nyxx.dart'; -import 'package:nyxx_commands/nyxx_commands.dart'; -import 'package:prometheus_client/prometheus_client.dart'; -import 'package:prometheus_client_shelf/shelf_handler.dart'; -import 'package:shelf/shelf.dart'; -import 'package:shelf/shelf_io.dart'; -import 'package:shelf_router/shelf_router.dart'; -import 'package:prometheus_client_shelf/shelf_metrics.dart' as shelf_metrics; -import 'package:prometheus_client/runtime_metrics.dart' as runtime_metrics; - -class PrometheusService { - static PrometheusService get instance => - _instance ?? - (throw Exception( - 'PrometheusService must be initialised with PrometheusService.init()')); - static PrometheusService? _instance; - - static void init(INyxxWebsocket client, CommandsPlugin commands) { - _instance = PrometheusService._(client, commands); - } - - final INyxxWebsocket client; - final CommandsPlugin commands; - final Logger _logger = Logger('ROD.Metrics'); - - PrometheusService._(this.client, this.commands) { - registerMetrics(); - startHttpServer(); - } - - void registerMetrics() { - runtime_metrics.register(); - - registerPeriodicCollectors(); - registerEventCollectors(); - registerCommandCollectors(); - } - - void registerPeriodicCollectors() { - final totalUsers = Gauge( - name: 'nyxx_total_users_cache', help: "Total number of users in cache") - ..register(); - final totalChannels = Gauge( - name: 'nyxx_total_channels_cache', - help: "Total number of channels in cache") - ..register(); - final messageCacheSize = Gauge( - name: 'nyxx_total_messages_cache', - help: "Total number of messages in cache") - ..register(); - final totalVoiceStates = Gauge( - name: 'nyxx_total_voice_states_cache', - help: "Total number of voice states in cache") - ..register(); - final shardWebsocketLatency = Gauge( - name: 'nyxx_ws_latency', - help: "Websocket latency", - labelNames: ['shard_id']) - ..register(); - - Timer.periodic(const Duration(seconds: 5), (timer) { - totalUsers.value = client.users.length.toDouble(); - totalChannels.value = client.channels.length.toDouble(); - messageCacheSize.value = client.channels.values - .whereType() - .fold(0, (count, channel) => count + channel.messageCache.length); - totalVoiceStates.value = client.guilds.values - .fold(0, (count, guild) => count + guild.voiceStates.length); - - for (final shard in client.shardManager.shards) { - shardWebsocketLatency.labels([shard.id.toString()]).value = - shard.gatewayLatency.inMilliseconds.toDouble(); - } - }); - } - - void registerEventCollectors() { - final totalMessagesSent = Counter( - name: 'nyxx_total_messages_sent', - help: "Total number of messages sent", - labelNames: ['guild_id']) - ..register(); - client.eventsWs.onMessageReceived.listen((event) => totalMessagesSent - .labels([event.message.guild?.id.toString() ?? 'dm']).inc()); - - final totalGuildJoins = Counter( - name: 'nyxx_total_guild_joins', - help: "Total number of guild joins", - labelNames: ['guild_id']) - ..register(); - client.eventsWs.onGuildMemberAdd.listen( - (event) => totalGuildJoins.labels([event.guild.id.toString()]).inc()); - - final httpResponses = Counter( - name: 'nyxx_http_response', - help: 'Code of http responses', - labelNames: ['code']) - ..register(); - client.eventsRest.onHttpResponse.listen((event) => - httpResponses.labels([event.response.statusCode.toString()]).inc()); - client.eventsRest.onHttpError.listen((event) => - httpResponses.labels([event.response.statusCode.toString()]).inc()); - client.eventsRest.onRateLimited - .listen((event) => httpResponses.labels(['429']).inc()); - } - - void registerCommandCollectors() { - final totalCommands = Counter( - name: 'nyxx_total_commands', - help: 'The total number of commands used', - labelNames: ['name']) - ..register(); - final totalSlashCommands = Counter( - name: 'nyxx_total_slash_commands', - help: 'The total number of slash commands used', - labelNames: ['name']) - ..register(); - final totalTextCommands = Counter( - name: 'nyxx_total_text_commands', - help: 'The total number of text commands used', - labelNames: ['name']) - ..register(); - - commands.onPreCall.listen((context) { - final name = context.command is ChatCommand - ? (context.command as ChatCommand).fullName - : context.command.name; - - totalCommands.labels([name]).inc(); - if (context is IInteractionContext) { - totalSlashCommands.labels([name]).inc(); - } else { - totalTextCommands.labels([name]).inc(); - } - }); - - final totalCommandsFailed = Counter( - name: 'nyxx_total_commands_failed', - help: 'The number of commands that failed', - labelNames: ['error', 'name']) - ..register(); - - commands.onCommandError.listen((error) { - if (error is CommandInvocationException) { - final name = error.context.command is ChatCommand - ? (error.context.command as ChatCommand).fullName - : error.context.command.name; - final errorName = (error is UncaughtException - ? error.exception.runtimeType - : error.runtimeType) - .toString(); - - totalCommandsFailed.labels([errorName, name]).inc(); - } - }); - - final commandExecutionTime = Histogram.exponential( - name: 'nyxx_command_execution_time', - help: 'The time each command took to execute', - start: 1, - factor: pow(const Duration(minutes: 15).inMicroseconds, 0.1).toDouble(), - count: 10, - labelNames: ['name'], - )..register(); - - final contextStartTimes = Expando(); - - commands.onPreCall - .listen((context) => contextStartTimes[context] = DateTime.now()); - - void handleDone(IContext context) { - final start = contextStartTimes[context]; - - if (start == null) { - return; - } - - final executionTime = DateTime.now().difference(start); - final name = context.command is ChatCommand - ? (context.command as ChatCommand).fullName - : context.command.name; - - commandExecutionTime - .labels([name]).observe(executionTime.inMilliseconds.toDouble()); - } - - commands.onPostCall.listen(handleDone); - commands.onCommandError - .where((error) => error is CommandInvocationException) - .cast() - .listen((error) => handleDone(error.context)); - } - - Future startHttpServer() async { - final router = Router()..get('/metrics', prometheusHandler()); - final handler = - Pipeline().addMiddleware(shelf_metrics.register()).addHandler(router); - - final server = await serve(handler, '0.0.0.0', 8080); - _logger.info('Serving at http://${server.address.host}:${server.port}'); - } -} diff --git a/lib/src/settings.dart b/lib/src/settings.dart index e6b893f..24bdcd9 100644 --- a/lib/src/settings.dart +++ b/lib/src/settings.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'package:nyxx/nyxx.dart'; -String get version => '3.3.1'; +String get version => '3.3.2'; /// Get a [String] from an environment variable, throwing an exception if it is not set. /// diff --git a/pubspec.yaml b/pubspec.yaml index ad9f8e8..fa6a5cf 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: running_on_dart -version: 3.3.1 +version: 3.3.2 description: Discord Bot for nyxx development homepage: https://github.com/nyxx-discord/running_on_dart repository: https://github.com/nyxx-discord/running_on_dart