Expose git version in 'pk;stats' and '/v1/meta'
This commit is contained in:
parent
dcc15dc847
commit
1cb4bc9287
@ -6,6 +6,7 @@
|
||||
!Myriad/
|
||||
!PluralKit.sln
|
||||
!nuget.config
|
||||
!.git
|
||||
|
||||
# Re-exclude host build artifact directories
|
||||
**/bin
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -20,3 +20,4 @@ pluralkit.*.conf
|
||||
|
||||
# Generated
|
||||
logs/
|
||||
.version
|
||||
|
@ -8,6 +8,7 @@ COPY PluralKit.API/PluralKit.API.csproj /app/PluralKit.API/
|
||||
COPY PluralKit.Bot/PluralKit.Bot.csproj /app/PluralKit.Bot/
|
||||
COPY PluralKit.Core/PluralKit.Core.csproj /app/PluralKit.Core/
|
||||
COPY PluralKit.Tests/PluralKit.Tests.csproj /app/PluralKit.Tests/
|
||||
COPY .git/ /app/.git
|
||||
RUN dotnet restore PluralKit.sln
|
||||
|
||||
# Copy the rest of the code and build
|
||||
|
@ -32,6 +32,7 @@ namespace PluralKit.API
|
||||
|
||||
var o = new JObject();
|
||||
o.Add("shards", shards.ToJSON());
|
||||
o.Add("version", BuildInfoService.Version);
|
||||
|
||||
return Ok(o);
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
using Autofac.Extensions.DependencyInjection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Autofac.Extensions.DependencyInjection;
|
||||
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@ -12,10 +14,11 @@ namespace PluralKit.API
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
InitUtils.InitStatic();
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
await BuildInfoService.LoadVersion();
|
||||
await CreateHostBuilder(args).Build().RunAsync();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
|
@ -92,7 +92,8 @@ namespace PluralKit.Bot {
|
||||
var process = Process.GetCurrentProcess();
|
||||
var memoryUsage = process.WorkingSet64;
|
||||
|
||||
var shardUptime = SystemClock.Instance.GetCurrentInstant() - shardInfo.LastConnectionTime;
|
||||
var now = SystemClock.Instance.GetCurrentInstant();
|
||||
var shardUptime = now - shardInfo.LastConnectionTime;
|
||||
|
||||
var embed = new EmbedBuilder();
|
||||
if (messagesReceived != null) embed.Field(new("Messages processed",$"{messagesReceived.OneMinuteRate * 60:F1}/m ({messagesReceived.FifteenMinuteRate * 60:F1}/m over 15m)", true));
|
||||
@ -105,7 +106,9 @@ namespace PluralKit.Bot {
|
||||
.Field(new("CPU usage", $"{_cpu.LastCpuMeasure:P1}", true))
|
||||
.Field(new("Memory usage", $"{memoryUsage / 1024 / 1024} MiB", true))
|
||||
.Field(new("Latency", $"API: {apiLatency.TotalMilliseconds:F0} ms, shard: {shardInfo.ShardLatency.Milliseconds} ms", true))
|
||||
.Field(new("Total numbers", $"{totalSystems:N0} systems, {totalMembers:N0} members, {totalGroups:N0} groups, {totalSwitches:N0} switches, {totalMessages:N0} messages"));
|
||||
.Field(new("Total numbers", $"{totalSystems:N0} systems, {totalMembers:N0} members, {totalGroups:N0} groups, {totalSwitches:N0} switches, {totalMessages:N0} messages"))
|
||||
.Timestamp(now.ToDateTimeOffset().ToString("O"))
|
||||
.Footer(new($"PluralKit {BuildInfoService.Version} • https://github.com/xSke/PluralKit"));;
|
||||
await ctx.Rest.EditMessage(msg.ChannelId, msg.Id,
|
||||
new MessageEditRequest {Content = "", Embed = embed.Build()});
|
||||
}
|
||||
|
@ -30,6 +30,9 @@ namespace PluralKit.Bot
|
||||
|
||||
return RunWrapper(services, async ct =>
|
||||
{
|
||||
// init version service
|
||||
await BuildInfoService.LoadVersion();
|
||||
|
||||
var logger = services.Resolve<ILogger>().ForContext<Init>();
|
||||
|
||||
// Initialize Sentry SDK, and make sure it gets dropped at the end
|
||||
|
@ -48,4 +48,16 @@
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Database/**/*.sql" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="SetSourceRevisionId" BeforeTargets="InitializeSourceControlInformation">
|
||||
<Exec
|
||||
Command="git describe --long --always --dirty --exclude=* --abbrev=8 > ../.version"
|
||||
IgnoreExitCode="False"
|
||||
>
|
||||
</Exec>
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\.version" LogicalName="version" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
24
PluralKit.Core/Services/BuildInfoService.cs
Normal file
24
PluralKit.Core/Services/BuildInfoService.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PluralKit.Core
|
||||
{
|
||||
public static class BuildInfoService
|
||||
{
|
||||
public static string Version { get; private set; }
|
||||
|
||||
public static async Task LoadVersion()
|
||||
{
|
||||
using (var stream = typeof(BuildInfoService).Assembly.GetManifestResourceStream("version"))
|
||||
{
|
||||
// if this happens, something broke
|
||||
if (stream == null) Version = "(unknown version) ";
|
||||
else using (var reader = new StreamReader(stream)) Version = await reader.ReadToEndAsync();
|
||||
}
|
||||
|
||||
// cheap hack to remove newline
|
||||
Version = Version.Remove(Version.Length - 1);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user