feat: expand mqtt varz monitoring with all Go-compatible fields
This commit is contained in:
@@ -355,8 +355,29 @@ public sealed class MqttOptsVarz
|
|||||||
[JsonPropertyName("port")]
|
[JsonPropertyName("port")]
|
||||||
public int Port { get; set; }
|
public int Port { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("no_auth_user")]
|
||||||
|
public string NoAuthUser { get; set; } = "";
|
||||||
|
|
||||||
|
[JsonPropertyName("auth_timeout")]
|
||||||
|
public double AuthTimeout { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("tls_map")]
|
||||||
|
public bool TlsMap { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("tls_timeout")]
|
[JsonPropertyName("tls_timeout")]
|
||||||
public double TlsTimeout { get; set; }
|
public double TlsTimeout { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("tls_pinned_certs")]
|
||||||
|
public string[] TlsPinnedCerts { get; set; } = [];
|
||||||
|
|
||||||
|
[JsonPropertyName("js_domain")]
|
||||||
|
public string JsDomain { get; set; } = "";
|
||||||
|
|
||||||
|
[JsonPropertyName("ack_wait")]
|
||||||
|
public long AckWait { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("max_ack_pending")]
|
||||||
|
public ushort MaxAckPending { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ public sealed class VarzHandler : IDisposable
|
|||||||
Subscriptions = _server.SubList.Count,
|
Subscriptions = _server.SubList.Count,
|
||||||
ConfigLoadTime = _server.StartTime,
|
ConfigLoadTime = _server.StartTime,
|
||||||
HttpReqStats = stats.HttpReqStats.ToDictionary(kv => kv.Key, kv => (ulong)kv.Value),
|
HttpReqStats = stats.HttpReqStats.ToDictionary(kv => kv.Key, kv => (ulong)kv.Value),
|
||||||
|
Mqtt = BuildMqttVarz(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@@ -134,6 +135,27 @@ public sealed class VarzHandler : IDisposable
|
|||||||
_varzMu.Dispose();
|
_varzMu.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MqttOptsVarz BuildMqttVarz()
|
||||||
|
{
|
||||||
|
var mqtt = _options.Mqtt;
|
||||||
|
if (mqtt is null)
|
||||||
|
return new MqttOptsVarz();
|
||||||
|
|
||||||
|
return new MqttOptsVarz
|
||||||
|
{
|
||||||
|
Host = mqtt.Host,
|
||||||
|
Port = mqtt.Port,
|
||||||
|
NoAuthUser = mqtt.NoAuthUser ?? "",
|
||||||
|
AuthTimeout = mqtt.AuthTimeout,
|
||||||
|
TlsMap = mqtt.TlsMap,
|
||||||
|
TlsTimeout = mqtt.TlsTimeout,
|
||||||
|
TlsPinnedCerts = mqtt.TlsPinnedCerts?.ToArray() ?? [],
|
||||||
|
JsDomain = mqtt.JsDomain ?? "",
|
||||||
|
AckWait = (long)mqtt.AckWait.TotalNanoseconds,
|
||||||
|
MaxAckPending = mqtt.MaxAckPending,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Formats a TimeSpan as a human-readable uptime string matching Go server format.
|
/// Formats a TimeSpan as a human-readable uptime string matching Go server format.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -271,6 +271,23 @@ public class MonitorTests : IAsyncLifetime
|
|||||||
response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Varz_includes_mqtt_section()
|
||||||
|
{
|
||||||
|
var response = await _http.GetAsync($"http://127.0.0.1:{_monitorPort}/varz");
|
||||||
|
response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
||||||
|
|
||||||
|
var varz = await response.Content.ReadFromJsonAsync<Varz>();
|
||||||
|
varz.ShouldNotBeNull();
|
||||||
|
varz.Mqtt.ShouldNotBeNull();
|
||||||
|
varz.Mqtt.Host.ShouldBe("");
|
||||||
|
varz.Mqtt.Port.ShouldBe(0);
|
||||||
|
varz.Mqtt.NoAuthUser.ShouldBe("");
|
||||||
|
varz.Mqtt.JsDomain.ShouldBe("");
|
||||||
|
varz.Mqtt.AckWait.ShouldBe(0L);
|
||||||
|
varz.Mqtt.MaxAckPending.ShouldBe((ushort)0);
|
||||||
|
}
|
||||||
|
|
||||||
private static int GetFreePort()
|
private static int GetFreePort()
|
||||||
{
|
{
|
||||||
using var sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
using var sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||||
|
|||||||
Reference in New Issue
Block a user