Skip to content

Commit

Permalink
Merge pull request #215 from coroot/fqdn_resolving
Browse files Browse the repository at this point in the history
resolve external service IPs to domain names
  • Loading branch information
def committed May 8, 2024
2 parents 0711697 + 65da0bc commit c354172
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
4 changes: 3 additions & 1 deletion constructor/constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,20 @@ 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) })
prof.stage("load_elasticache_metadata", func() { loadElasticacheMetadata(w, metrics, pjs, ecInstancesById) })
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) })
Expand Down
8 changes: 6 additions & 2 deletions constructor/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions constructor/fqdn.go
Original file line number Diff line number Diff line change
@@ -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"])
}
}
1 change: 1 addition & 0 deletions constructor/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}`,
Expand Down
2 changes: 1 addition & 1 deletion front/src/views/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<v-list-item-title class="ml-3">
<Led :status="a.status" />
<span>{{ a.name }}</span>
<span v-if="a.ns" class="caption">(ns: {{ a.ns }})</span>
<span v-if="a.ns" class="caption"> (ns: {{ a.ns }})</span>
</v-list-item-title>
</v-list-item>
</template>
Expand Down

0 comments on commit c354172

Please sign in to comment.