Skip to content

Commit

Permalink
Don't log remote API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Equinox- committed Mar 30, 2024
1 parent 90480d7 commit afa97f5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Meds.Wrapper/MedsCoreSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ protected override void Start()
{
PatchHelper.PatchAlways(true);
if (Config.Metrics.PrometheusKey != null)
{
PatchHelper.Patch(typeof(PrometheusPatch));
PatchHelper.Patch(typeof(RemoteServerLessLogging));
}

if (Config.Metrics.Network)
TransportLayerMetrics.Register();
if (Config.Metrics.Player)
Expand Down
36 changes: 36 additions & 0 deletions Meds.Wrapper/Output/Prometheus/PrometheusPatch.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Reflection.Emit;
using HarmonyLib;
using Meds.Metrics;
using VRage.Dedicated.RemoteAPI;
using VRage.Logging;

namespace Meds.Wrapper.Output.Prometheus
{
Expand Down Expand Up @@ -45,4 +50,35 @@ public static bool Prefix(HttpListenerContext context)
return false;
}
}

[HarmonyPatch(typeof(MyRemoteServer), "Listen")]
public sealed class RemoteServerLessLogging
{
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var removeLogTriggers = new[] { "Received request from", "URL:", "HTTP Method", "Request processed in" };
var removingLog = false;
foreach (var instruction in instructions)
{
if (instruction.opcode == OpCodes.Ldstr && instruction.operand is string str && removeLogTriggers.Any(trigger => str.Contains(trigger)))
removingLog = true;
if (removingLog
&& instruction.operand is MethodInfo { IsStatic: false } method
&& method.ReturnType == typeof(void)
&& (method.DeclaringType == typeof(MyLog) || method.DeclaringType == typeof(NamedLogger))
&& !(method.Name == nameof(NamedLogger.OpenBlock) || method.Name == nameof(MyLog.IncreaseIndent) ||
method.Name == nameof(MyLog.DecreaseIndent)))
{
yield return new CodeInstruction(OpCodes.Nop).WithBlocks(instruction.blocks).WithLabels(instruction.labels);
var pops = 1 + method.GetParameters().Length;
for (var i = 0; i < pops; i++)
yield return new CodeInstruction(OpCodes.Pop);
removingLog = false;
continue;
}

yield return instruction;
}
}
}
}

0 comments on commit afa97f5

Please sign in to comment.