mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
feat(bot): run both local and http cache to log differences
This commit is contained in:
parent
9aad6f329c
commit
f1ad221b0f
5 changed files with 150 additions and 29 deletions
|
|
@ -99,13 +99,9 @@ public class Bot
|
|||
|
||||
private async Task OnEventReceived(int shardId, IGatewayEvent evt)
|
||||
{
|
||||
if (_cache is MemoryDiscordCache)
|
||||
{
|
||||
// we HandleGatewayEvent **before** getting the own user, because the own user is set in HandleGatewayEvent for ReadyEvent
|
||||
await _cache.HandleGatewayEvent(evt);
|
||||
|
||||
await _cache.TryUpdateSelfMember(_config.ClientId, evt);
|
||||
}
|
||||
// we HandleGatewayEvent **before** getting the own user, because the own user is set in HandleGatewayEvent for ReadyEvent
|
||||
await _cache.HandleGatewayEvent(evt);
|
||||
await _cache.TryUpdateSelfMember(_config.ClientId, evt);
|
||||
await OnEventReceivedInner(shardId, evt);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -136,4 +136,11 @@ public static class BotMetrics
|
|||
DurationUnit = TimeUnit.Seconds,
|
||||
Context = "Bot"
|
||||
};
|
||||
|
||||
public static MeterOptions CacheDebug => new()
|
||||
{
|
||||
Name = "Bad responses to cache lookups",
|
||||
Context = "Bot",
|
||||
MeasurementUnit = Unit.Calls
|
||||
};
|
||||
}
|
||||
|
|
@ -49,9 +49,24 @@ public class BotModule: Module
|
|||
var botConfig = c.Resolve<BotConfig>();
|
||||
|
||||
if (botConfig.HttpCacheUrl != null)
|
||||
return new HttpDiscordCache(c.Resolve<ILogger>(),
|
||||
{
|
||||
var cache = new HttpDiscordCache(c.Resolve<ILogger>(),
|
||||
c.Resolve<HttpClient>(), botConfig.HttpCacheUrl, botConfig.Cluster?.TotalShards ?? 1, botConfig.ClientId);
|
||||
|
||||
var metrics = c.Resolve<IMetrics>();
|
||||
|
||||
cache.OnDebug += (_, ev) =>
|
||||
{
|
||||
var (remote, key) = ev;
|
||||
metrics.Measure.Meter.Mark(BotMetrics.CacheDebug, new MetricTags(
|
||||
new[] { "remote", "key" },
|
||||
new[] { remote.ToString(), key }
|
||||
));
|
||||
};
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
return new MemoryDiscordCache(botConfig.ClientId);
|
||||
}).AsSelf().SingleInstance();
|
||||
builder.RegisterType<PrivateChannelService>().AsSelf().SingleInstance();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue