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

Add method for publishing messages to redis channels #24

Merged
merged 2 commits into from
Dec 20, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Track count of messages published
bdach committed Dec 19, 2022

Verified

This commit was signed with the committer’s verified signature.
bdach Bartłomiej Dach
commit a6056b1f88abace19b0308c8644996ead396c2b5
10 changes: 8 additions & 2 deletions osu.Server.QueueProcessor/QueueProcessor.cs
Original file line number Diff line number Diff line change
@@ -233,13 +233,19 @@ public long GetQueueSize() =>

/// <summary>
/// Publishes a message to a Redis channel with the supplied <paramref name="channelName"/>.
/// The message will be serialised using JSON.
/// </summary>
/// <remarks>
/// The message will be serialised using JSON.
/// Successful publications are tracked in Datadog, using the <paramref name="channelName"/> and the <typeparamref name="TMessage"/>'s full type name as a tag.
/// </remarks>
/// <param name="channelName">The name of the Redis channel to publish to.</param>
/// <param name="message">The message to publish to the channel.</param>
/// <typeparam name="TMessage">The type of message to be published.</typeparam>
public void PublishMessage<TMessage>(string channelName, TMessage message) =>
public void PublishMessage<TMessage>(string channelName, TMessage message)
{
redis.GetDatabase().Publish(channelName, JsonConvert.SerializeObject(message));
DogStatsd.Increment("messages_published", tags: new[] { $"channel:{channelName}", $"type:{typeof(TMessage).FullName}" });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dunno if this is overkill or not. Given that Redis's pubsub is a no-guarantees implementation, it felt like it may be nice to get counts from the publisher directly? I don't see datadog having anything in-house that could add this sort of tracking. Definitely think it's a good idea to have some sort of observability at a few stages of this flow to be able to diagnose failures better, though.

}

/// <summary>
/// Retrieve a database connection.