Restores metrics
This commit is contained in:
parent
dc9f3ab090
commit
4f9c0e0ce7
|
@ -109,32 +109,6 @@ namespace KubernetesWorkflow
|
|||
}
|
||||
}
|
||||
|
||||
public class RunningPod
|
||||
{
|
||||
public RunningPod(K8sCluster cluster, PodInfo podInfo, string deploymentName, string serviceName, ContainerRecipePortMapEntry[] portMapEntries)
|
||||
{
|
||||
Cluster = cluster;
|
||||
PodInfo = podInfo;
|
||||
DeploymentName = deploymentName;
|
||||
ServiceName = serviceName;
|
||||
PortMapEntries = portMapEntries;
|
||||
}
|
||||
|
||||
public K8sCluster Cluster { get; }
|
||||
public PodInfo PodInfo { get; }
|
||||
public ContainerRecipePortMapEntry[] PortMapEntries { get; }
|
||||
public string DeploymentName { get; }
|
||||
public string ServiceName { get; }
|
||||
|
||||
public Port[] GetServicePortsForContainerRecipe(ContainerRecipe containerRecipe)
|
||||
{
|
||||
return PortMapEntries
|
||||
.Where(p => p.RecipeNumber == containerRecipe.Number)
|
||||
.SelectMany(p => p.Ports)
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public class ContainerRecipePortMapEntry
|
||||
{
|
||||
public ContainerRecipePortMapEntry(int recipeNumber, Port[] ports)
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace MetricsPlugin
|
|||
{
|
||||
this.query = query;
|
||||
this.target = target;
|
||||
TargetName = target.Name;
|
||||
TargetName = target.Container.Name;
|
||||
}
|
||||
|
||||
public string TargetName { get; }
|
||||
|
|
|
@ -122,7 +122,7 @@ namespace MetricsPlugin
|
|||
|
||||
private string GetInstanceNameForNode(IMetricsScrapeTarget target)
|
||||
{
|
||||
return target.Address.ToString();
|
||||
return ScrapeTargetHelper.FormatTarget(target);
|
||||
}
|
||||
|
||||
private string GetInstanceStringForNode(IMetricsScrapeTarget target)
|
||||
|
@ -148,7 +148,7 @@ namespace MetricsPlugin
|
|||
|
||||
private void Log(IMetricsScrapeTarget target, string metricName, Metrics result)
|
||||
{
|
||||
Log($"{target.Name} '{metricName}' = {result}");
|
||||
Log($"{target.Container.Name} '{metricName}' = {result}");
|
||||
}
|
||||
|
||||
private void Log(string metricName, Metrics result)
|
||||
|
@ -158,7 +158,7 @@ namespace MetricsPlugin
|
|||
|
||||
private void Log(IMetricsScrapeTarget target, Metrics result)
|
||||
{
|
||||
Log($"{target.Name} => {result}");
|
||||
Log($"{target.Container.Name} => {result}");
|
||||
}
|
||||
|
||||
private void Log(string msg)
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
using KubernetesWorkflow;
|
||||
using Utils;
|
||||
|
||||
namespace MetricsPlugin
|
||||
{
|
||||
public interface IMetricsScrapeTarget
|
||||
{
|
||||
string Name { get; }
|
||||
Address Address { get; }
|
||||
RunningContainer Container { get; }
|
||||
string MetricsPortTag { get; }
|
||||
}
|
||||
|
||||
public interface IHasMetricsScrapeTarget
|
||||
|
@ -21,23 +20,13 @@ namespace MetricsPlugin
|
|||
|
||||
public class MetricsScrapeTarget : IMetricsScrapeTarget
|
||||
{
|
||||
public MetricsScrapeTarget(Address address, string name)
|
||||
public MetricsScrapeTarget(RunningContainer container, string metricsPortTag)
|
||||
{
|
||||
Address = address;
|
||||
Name = name;
|
||||
Container = container;
|
||||
MetricsPortTag = metricsPortTag;
|
||||
}
|
||||
|
||||
public MetricsScrapeTarget(string ip, int port, string name)
|
||||
: this(new Address("http://" + ip, port), name)
|
||||
{
|
||||
}
|
||||
|
||||
public MetricsScrapeTarget(RunningContainer container, string portTag)
|
||||
: this(container.GetAddress(portTag), container.Name)
|
||||
{
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
public Address Address { get; }
|
||||
public RunningContainer Container { get; }
|
||||
public string MetricsPortTag { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace MetricsPlugin
|
|||
tools.GetLog().Log(msg);
|
||||
}
|
||||
|
||||
private static string GeneratePrometheusConfig(IMetricsScrapeTarget[] targets)
|
||||
private string GeneratePrometheusConfig(IMetricsScrapeTarget[] targets)
|
||||
{
|
||||
var config = "";
|
||||
config += "global:\n";
|
||||
|
@ -59,11 +59,26 @@ namespace MetricsPlugin
|
|||
|
||||
foreach (var target in targets)
|
||||
{
|
||||
config += $" - '{target.Address.Host}:{target.Address.Port}'\n";
|
||||
config += $" - '{FormatTarget(target)}'\n";
|
||||
}
|
||||
|
||||
var bytes = Encoding.ASCII.GetBytes(config);
|
||||
return Convert.ToBase64String(bytes);
|
||||
}
|
||||
|
||||
private string FormatTarget(IMetricsScrapeTarget target)
|
||||
{
|
||||
return ScrapeTargetHelper.FormatTarget(target);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ScrapeTargetHelper
|
||||
{
|
||||
public static string FormatTarget(IMetricsScrapeTarget target)
|
||||
{
|
||||
var a = target.Container.GetAddress(target.MetricsPortTag);
|
||||
var host = a.Host.Replace("http://", "").Replace("https://", "");
|
||||
return $"{host}:{a.Port}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue