From 65da0bcf038efa136bdd566c7a77821f85a1e69a Mon Sep 17 00:00:00 2001 From: Nikolay Sivko Date: Wed, 8 May 2024 14:25:53 +0300 Subject: [PATCH] resolve external service IPs to domain names --- constructor/constructor.go | 4 +++- constructor/containers.go | 8 ++++++-- constructor/fqdn.go | 15 +++++++++++++++ constructor/queries.go | 1 + front/src/views/Search.vue | 2 +- 5 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 constructor/fqdn.go diff --git a/constructor/constructor.go b/constructor/constructor.go index f38304cec..a8b4cba9f 100644 --- a/constructor/constructor.go +++ b/constructor/constructor.go @@ -100,10 +100,12 @@ func (c *Constructor) LoadWorld(ctx context.Context, from, to timeseries.Time, s rdsInstancesById := map[string]*model.Instance{} ecInstancesById := map[string]*model.Instance{} servicesByClusterIP := map[string]*model.Service{} + ip2fqdn := map[string]*model.LabelLastValue{} // order is important prof.stage("load_job_statuses", func() { loadPromJobStatuses(metrics, pjs) }) prof.stage("load_nodes", func() { c.loadNodes(w, metrics, nodesByMachineId) }) + prof.stage("load_fqdn", func() { loadFQDNs(metrics, ip2fqdn) }) prof.stage("load_fargate_nodes", func() { c.loadFargateNodes(metrics, nodesByMachineId) }) prof.stage("load_k8s_metadata", func() { loadKubernetesMetadata(w, metrics, servicesByClusterIP) }) prof.stage("load_rds_metadata", func() { loadRdsMetadata(w, metrics, pjs, rdsInstancesById) }) @@ -111,7 +113,7 @@ func (c *Constructor) LoadWorld(ctx context.Context, from, to timeseries.Time, s prof.stage("load_rds", func() { c.loadRds(w, metrics, pjs, rdsInstancesById) }) prof.stage("load_elasticache", func() { c.loadElasticache(w, metrics, pjs, ecInstancesById) }) prof.stage("load_fargate_containers", func() { loadFargateContainers(w, metrics, pjs) }) - prof.stage("load_containers", func() { loadContainers(w, metrics, pjs, nodesByMachineId, servicesByClusterIP) }) + prof.stage("load_containers", func() { loadContainers(w, metrics, pjs, nodesByMachineId, servicesByClusterIP, ip2fqdn) }) prof.stage("enrich_instances", func() { enrichInstances(w, metrics, rdsInstancesById, ecInstancesById) }) prof.stage("join_db_cluster", func() { joinDBClusterComponents(w) }) prof.stage("calc_app_categories", func() { c.calcApplicationCategories(w) }) diff --git a/constructor/containers.go b/constructor/containers.go index 4bd8139b8..fea134344 100644 --- a/constructor/containers.go +++ b/constructor/containers.go @@ -62,7 +62,7 @@ func getInstanceAndContainer(w *model.World, node *model.Node, instances map[ins return instance, instance.GetOrCreateContainer(containerId, containerName) } -func loadContainers(w *model.World, metrics map[string][]model.MetricValues, pjs promJobStatuses, nodesByMachineId map[string]*model.Node, servicesByClusterIP map[string]*model.Service) { +func loadContainers(w *model.World, metrics map[string][]model.MetricValues, pjs promJobStatuses, nodesByMachineId map[string]*model.Node, servicesByClusterIP map[string]*model.Service, ip2fqdn map[string]*model.LabelLastValue) { instances := map[instanceId]*model.Instance{} for _, a := range w.Applications { for _, i := range a.Instances { @@ -270,7 +270,11 @@ func loadContainers(w *model.World, metrics map[string][]model.MetricValues, pjs appId.Name = svc.Name } } else { - appId.Name = externalServiceName(u.ActualRemotePort) + if fqdn := ip2fqdn[u.ActualRemoteIP]; fqdn != nil { + appId.Name = fqdn.Value() + ":" + u.ActualRemotePort + } else { + appId.Name = externalServiceName(u.ActualRemotePort) + } } ri := w.GetOrCreateApplication(appId).GetOrCreateInstance(u.ActualRemoteIP+":"+u.ActualRemotePort, nil) ri.TcpListens[model.Listen{IP: u.ActualRemoteIP, Port: u.ActualRemotePort}] = true diff --git a/constructor/fqdn.go b/constructor/fqdn.go new file mode 100644 index 000000000..d99405319 --- /dev/null +++ b/constructor/fqdn.go @@ -0,0 +1,15 @@ +package constructor + +import "github.com/coroot/coroot/model" + +func loadFQDNs(metrics map[string][]model.MetricValues, ip2fqdn map[string]*model.LabelLastValue) { + for _, m := range metrics["ip_to_fqdn"] { + ip := m.Labels["ip"] + v := ip2fqdn[ip] + if v == nil { + v = &model.LabelLastValue{} + ip2fqdn[ip] = v + } + v.Update(m.Values, m.Labels["fqdn"]) + } +} diff --git a/constructor/queries.go b/constructor/queries.go index 2ee56606d..5c1d667b9 100644 --- a/constructor/queries.go +++ b/constructor/queries.go @@ -41,6 +41,7 @@ var QUERIES = map[string]string{ "node_net_ip": `node_net_interface_ip`, "node_net_rx_bytes": `rate(node_net_received_bytes_total[$RANGE])`, "node_net_tx_bytes": `rate(node_net_transmitted_bytes_total[$RANGE])`, + "ip_to_fqdn": `ip_to_fqdn`, "fargate_node_machine_cpu_cores": `machine_cpu_cores{eks_amazonaws_com_compute_type="fargate"}`, "fargate_node_machine_memory_bytes": `machine_memory_bytes{eks_amazonaws_com_compute_type="fargate"}`, diff --git a/front/src/views/Search.vue b/front/src/views/Search.vue index 9f31d64c0..6ed69c303 100644 --- a/front/src/views/Search.vue +++ b/front/src/views/Search.vue @@ -31,7 +31,7 @@ {{ a.name }} - (ns: {{ a.ns }}) + (ns: {{ a.ns }})