mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
refactor: remove protobuf
This commit is contained in:
parent
f1685495eb
commit
4596d98670
31 changed files with 58 additions and 577 deletions
|
|
@ -94,7 +94,7 @@ public class Misc
|
|||
var memoryUsage = process.WorkingSet64;
|
||||
|
||||
var now = SystemClock.Instance.GetCurrentInstant().ToUnixTimeSeconds();
|
||||
var shardUptime = Duration.FromSeconds(now - shardInfo?.LastConnection ?? 0);
|
||||
var shardUptime = Duration.FromSeconds(now - shardInfo.LastConnection);
|
||||
|
||||
var shardTotal = _botConfig.Cluster?.TotalShards ?? shards.Count();
|
||||
int shardClusterTotal = ctx.Cluster.Shards.Count;
|
||||
|
|
@ -106,11 +106,11 @@ public class Misc
|
|||
+ (isCluster ? $" {shardClusterTotal} in this cluster," : "") + $" {shardUpTotal} are up)"
|
||||
, true))
|
||||
.Field(new Embed.Field("Shard uptime",
|
||||
$"{shardUptime.FormatDuration()} ({shardInfo?.DisconnectionCount} disconnections)", true))
|
||||
$"{shardUptime.FormatDuration()} ({shardInfo.DisconnectionCount} disconnections)", true))
|
||||
.Field(new Embed.Field("CPU usage", $"{_cpu.LastCpuMeasure:P1}", true))
|
||||
.Field(new Embed.Field("Memory usage", $"{memoryUsage / 1024 / 1024} MiB", true))
|
||||
.Field(new Embed.Field("Latency",
|
||||
$"API: {apiLatency.TotalMilliseconds:F0} ms, shard: {shardInfo?.Latency} ms",
|
||||
$"API: {apiLatency.TotalMilliseconds:F0} ms, shard: {shardInfo.Latency} ms",
|
||||
true));
|
||||
|
||||
embed.Field(new("Total numbers", $" {counts.SystemCount:N0} systems,"
|
||||
|
|
|
|||
|
|
@ -22,15 +22,8 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Google.Protobuf" Version="3.29.1" />
|
||||
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.67.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.68.1" PrivateAssets="all" />
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||
<PackageReference Include="Sentry" Version="4.13.0" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Protobuf Include="../proto/state.proto" GrpcServices="Client" Link="Protos/state.proto" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
using System.Net.WebSockets;
|
||||
|
||||
using Google.Protobuf;
|
||||
|
||||
using Myriad.Gateway;
|
||||
|
||||
using NodaTime;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using StackExchange.Redis;
|
||||
|
||||
using PluralKit.Core;
|
||||
|
|
@ -14,6 +14,17 @@ using Serilog;
|
|||
|
||||
namespace PluralKit.Bot;
|
||||
|
||||
public struct ShardState
|
||||
{
|
||||
[JsonProperty("shard_id")] public int ShardId;
|
||||
[JsonProperty("up")] public bool Up;
|
||||
[JsonProperty("disconnection_count")] public int DisconnectionCount;
|
||||
[JsonProperty("latency")] public int Latency;
|
||||
[JsonProperty("last_heartbeat")] public int LastHeartbeat;
|
||||
[JsonProperty("last_connection")] public int LastConnection;
|
||||
[JsonProperty("cluster_id")] public int? ClusterId;
|
||||
}
|
||||
|
||||
public class ShardInfoService
|
||||
{
|
||||
private readonly int? _clusterId;
|
||||
|
|
@ -43,7 +54,7 @@ public class ShardInfoService
|
|||
return new ShardState[] { };
|
||||
var db = _redis.Connection.GetDatabase();
|
||||
var redisInfo = await db.HashGetAllAsync("pluralkit:shardstatus");
|
||||
return redisInfo.Select(x => Proto.Unmarshal<ShardState>(x.Value));
|
||||
return redisInfo.Select(x => JsonConvert.DeserializeObject<ShardState>(x.Value));
|
||||
}
|
||||
|
||||
private void InitializeShard(Shard shard)
|
||||
|
|
@ -53,13 +64,8 @@ public class ShardInfoService
|
|||
async Task Inner()
|
||||
{
|
||||
var db = _redis.Connection.GetDatabase();
|
||||
var redisInfo = await db.HashGetAsync("pluralkit::shardstatus", shard.ShardId);
|
||||
|
||||
// Skip adding listeners if we've seen this shard & already added listeners to it
|
||||
if (redisInfo.HasValue)
|
||||
return;
|
||||
|
||||
// latency = 0 because otherwise shard 0 would serialize to an empty array, thanks protobuf
|
||||
// latency = 1 because otherwise shard 0 would serialize to an empty array, thanks protobuf
|
||||
var state = new ShardState() { ShardId = shard.ShardId, Up = false, Latency = 1 };
|
||||
if (_clusterId != null)
|
||||
state.ClusterId = _clusterId.Value;
|
||||
|
|
@ -75,13 +81,13 @@ public class ShardInfoService
|
|||
}
|
||||
}
|
||||
|
||||
private async Task<ShardState?> TryGetShard(Shard shard)
|
||||
private async Task<ShardState> TryGetShard(Shard shard)
|
||||
{
|
||||
var db = _redis.Connection.GetDatabase();
|
||||
var redisInfo = await db.HashGetAsync("pluralkit:shardstatus", shard.ShardId);
|
||||
if (redisInfo.HasValue)
|
||||
return Proto.Unmarshal<ShardState>(redisInfo);
|
||||
return null;
|
||||
return JsonConvert.DeserializeObject<ShardState>(redisInfo);
|
||||
throw new Exception("expected shard, but didn't get one");
|
||||
}
|
||||
|
||||
private void ReadyOrResumed(Shard shard)
|
||||
|
|
@ -145,5 +151,5 @@ public static class RedisExt
|
|||
{
|
||||
// convenience method
|
||||
public static HashEntry[] HashWrapper(this ShardState state)
|
||||
=> new[] { new HashEntry(state.ShardId, state.ToByteArray()) };
|
||||
=> new[] { new HashEntry(state.ShardId, JsonConvert.SerializeObject(state)) };
|
||||
}
|
||||
|
|
@ -2,28 +2,6 @@
|
|||
"version": 1,
|
||||
"dependencies": {
|
||||
"net8.0": {
|
||||
"Google.Protobuf": {
|
||||
"type": "Direct",
|
||||
"requested": "[3.29.1, )",
|
||||
"resolved": "3.29.1",
|
||||
"contentHash": "kDFLP72bPu4GwquVN7HtFnfqxhQs4CLbUEyOc/0yV48HB0Pxf7tDK7zIx6ifaQwGp+RSoLY1sz1CXqoAEAu+AQ=="
|
||||
},
|
||||
"Grpc.Net.ClientFactory": {
|
||||
"type": "Direct",
|
||||
"requested": "[2.67.0, )",
|
||||
"resolved": "2.67.0",
|
||||
"contentHash": "owkRL6j8ZXvLnn8SsFGCRiWoe/2wGv+u+TASAylzUtGbHLnw7IiFRoeTs0IgpCNTETvlMLVb0gHDiLGo+mJZ6g==",
|
||||
"dependencies": {
|
||||
"Grpc.Net.Client": "2.67.0",
|
||||
"Microsoft.Extensions.Http": "6.0.0"
|
||||
}
|
||||
},
|
||||
"Grpc.Tools": {
|
||||
"type": "Direct",
|
||||
"requested": "[2.68.1, )",
|
||||
"resolved": "2.68.1",
|
||||
"contentHash": "BZ96s7ijKAhJoRpIK+pqCeLaGaSwyc5/CAZFwgCcBuAnkU2naYvH0P6qnYCkl0pWDY/JBOnE2RvX9IvRX1Yc5Q=="
|
||||
},
|
||||
"Humanizer.Core": {
|
||||
"type": "Direct",
|
||||
"requested": "[2.14.1, )",
|
||||
|
|
@ -158,28 +136,6 @@
|
|||
"System.Diagnostics.DiagnosticSource": "5.0.0"
|
||||
}
|
||||
},
|
||||
"Grpc.Core.Api": {
|
||||
"type": "Transitive",
|
||||
"resolved": "2.67.0",
|
||||
"contentHash": "cL1/2f8kc8lsAGNdfCU25deedXVehhLA6GXKLLN4hAWx16XN7BmjYn3gFU+FBpir5yJynvDTHEypr3Tl0j7x/Q=="
|
||||
},
|
||||
"Grpc.Net.Client": {
|
||||
"type": "Transitive",
|
||||
"resolved": "2.67.0",
|
||||
"contentHash": "ofTjJQfegWkVlk5R4k/LlwpcucpsBzntygd4iAeuKd/eLMkmBWoXN+xcjYJ5IibAahRpIJU461jABZvT6E9dwA==",
|
||||
"dependencies": {
|
||||
"Grpc.Net.Common": "2.67.0",
|
||||
"Microsoft.Extensions.Logging.Abstractions": "6.0.0"
|
||||
}
|
||||
},
|
||||
"Grpc.Net.Common": {
|
||||
"type": "Transitive",
|
||||
"resolved": "2.67.0",
|
||||
"contentHash": "gazn1cD2Eol0/W5ZJRV4PYbNrxJ9oMs8pGYux5S9E4MymClvl7aqYSmpqgmWAUWvziRqK9K+yt3cjCMfQ3x/5A==",
|
||||
"dependencies": {
|
||||
"Grpc.Core.Api": "2.67.0"
|
||||
}
|
||||
},
|
||||
"IPNetwork2": {
|
||||
"type": "Transitive",
|
||||
"resolved": "3.0.667",
|
||||
|
|
@ -318,17 +274,6 @@
|
|||
"resolved": "9.0.0",
|
||||
"contentHash": "jGFKZiXs2HNseK3NK/rfwHNNovER71jSj4BD1a/649ml9+h6oEtYd0GSALZDNW8jZ2Rh+oAeadOa6sagYW1F2A=="
|
||||
},
|
||||
"Microsoft.Extensions.Http": {
|
||||
"type": "Transitive",
|
||||
"resolved": "6.0.0",
|
||||
"contentHash": "15+pa2G0bAMHbHewaQIdr/y6ag2H3yh4rd9hTXavtWDzQBkvpe2RMqFg8BxDpcQWssmjmBApGPcw93QRz6YcMg==",
|
||||
"dependencies": {
|
||||
"Microsoft.Extensions.DependencyInjection.Abstractions": "6.0.0",
|
||||
"Microsoft.Extensions.Logging": "6.0.0",
|
||||
"Microsoft.Extensions.Logging.Abstractions": "6.0.0",
|
||||
"Microsoft.Extensions.Options": "6.0.0"
|
||||
}
|
||||
},
|
||||
"Microsoft.Extensions.Logging": {
|
||||
"type": "Transitive",
|
||||
"resolved": "9.0.0",
|
||||
|
|
@ -778,8 +723,6 @@
|
|||
"myriad": {
|
||||
"type": "Project",
|
||||
"dependencies": {
|
||||
"Google.Protobuf": "[3.29.1, )",
|
||||
"Grpc.Net.ClientFactory": "[2.67.0, )",
|
||||
"Polly": "[8.5.0, )",
|
||||
"Polly.Contrib.WaitAndRetry": "[1.1.1, )",
|
||||
"Serilog": "[4.2.0, )",
|
||||
|
|
@ -797,7 +740,6 @@
|
|||
"Autofac.Extensions.DependencyInjection": "[10.0.0, )",
|
||||
"Dapper": "[2.1.35, )",
|
||||
"Dapper.Contrib": "[2.0.78, )",
|
||||
"Google.Protobuf": "[3.29.1, )",
|
||||
"Microsoft.Extensions.Caching.Memory": "[9.0.0, )",
|
||||
"Microsoft.Extensions.Configuration": "[9.0.0, )",
|
||||
"Microsoft.Extensions.Configuration.Binder": "[9.0.0, )",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue