Skip to content

Commit 8a94bea

Browse files
craig[bot]golgeek
andcommitted
Merge #149369
149369: roachprod: scrape workload metrics via promhelperservice r=DarrylWong,herkolategan a=golgeek This patch adds the workload metrics ports range (2112-2120) to the scrape targets handled by promhelperservice to allow scraping of workload metrics in all Cloud providers. For releases prior to 25.3 (this patch will be backported to 25.3), workload metrics will only be scraped in GCE by the gce_sd_config Prometheus discovery mechanism. Epic: none Release note: None Co-authored-by: Ludovic Leroux <[email protected]>
2 parents 923e3b0 + 420fcbc commit 8a94bea

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

pkg/roachprod/roachprod.go

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -836,33 +836,51 @@ func updatePrometheusTargets(
836836
l.Errorf("error getting the port for node %d: %v", nodeID, err)
837837
return
838838
}
839+
839840
nodeIP := v.PrivateIP
840841
if reachability == promhelperclient.Public {
841842
nodeIP = v.PublicIP
842843
}
843-
nodeInfo := fmt.Sprintf("%s:%d", nodeIP, desc.Port)
844-
nodeIPPortsMutex.Lock()
844+
845845
// ensure atomicity in map update
846+
nodeIPPortsMutex.Lock()
847+
defer nodeIPPortsMutex.Unlock()
848+
849+
// Hardware metrics
846850
if _, ok := nodeIPPorts[nodeID]; !ok {
847851
nodeIPPorts[nodeID] = []*promhelperclient.NodeInfo{
848852
{
849853
Target: fmt.Sprintf("%s:%d", nodeIP, vm.NodeExporterPort),
850-
CustomLabels: createLabels(nodeID, v, "node_exporter", !c.Secure),
854+
CustomLabels: createLabels(nodeID, v, "node_exporter", false),
851855
},
852856
{
853857
Target: fmt.Sprintf("%s:%d", nodeIP, vm.EbpfExporterPort),
854-
CustomLabels: createLabels(nodeID, v, "ebpf_exporter", !c.Secure),
858+
CustomLabels: createLabels(nodeID, v, "ebpf_exporter", false),
855859
},
856860
}
857861
}
862+
863+
// CRDB metrics
858864
nodeIPPorts[nodeID] = append(
859865
nodeIPPorts[nodeID],
860866
&promhelperclient.NodeInfo{
861-
Target: nodeInfo,
867+
Target: fmt.Sprintf("%s:%d", nodeIP, desc.Port),
862868
CustomLabels: createLabels(nodeID, v, "cockroachdb", !c.Secure),
863869
},
864870
)
865-
nodeIPPortsMutex.Unlock()
871+
872+
// Workload metrics
873+
// TODO (golgeek): find a way to figure out if workload will be running
874+
// on the node and only scrape its actual metrics port?
875+
for port := vm.WorkloadMetricsPortMin; port <= vm.WorkloadMetricsPortMax; port++ {
876+
nodeIPPorts[nodeID] = append(
877+
nodeIPPorts[nodeID],
878+
&promhelperclient.NodeInfo{
879+
Target: fmt.Sprintf("%s:%d", nodeIP, port),
880+
CustomLabels: createLabels(nodeID, v, "workload", false),
881+
},
882+
)
883+
}
866884
}(int(node), c.VMs[node-1])
867885

868886
}
@@ -902,26 +920,26 @@ func createLabels(nodeID int, v vm.VM, job string, insecure bool) map[string]str
902920
if t, ok := v.Labels["test_run_id"]; ok {
903921
labels["test_run_id"] = t
904922
}
923+
924+
// Default configuration for promhelperservice is HTTPS but insecure exporters
925+
// are scraped over HTTP.
926+
if insecure {
927+
labels["__scheme__"] = "http"
928+
}
929+
905930
switch job {
906931
case "cockroachdb":
907932
labels["__metrics_path__"] = "/_status/vars"
908-
if insecure {
909-
labels["__scheme__"] = "http"
910-
}
911933
case "node_exporter":
912934
labels["__metrics_path__"] = vm.NodeExporterMetricsPath
913-
// node_exporter is always scraped over http
914-
labels["__scheme__"] = "http"
915-
916-
// Node ID is exposed by cockroachdb metrics, we add it to node_exporter
917-
labels["node_id"] = strconv.Itoa(nodeID)
918-
919935
case "ebpf_exporter":
920936
labels["__metrics_path__"] = vm.EbpfExporterMetricsPath
921-
// ebpf_exporter is always scraped over http
922-
labels["__scheme__"] = "http"
937+
case "workload":
938+
labels["__metrics_path__"] = vm.WorkloadMetricsPath
939+
}
923940

924-
// Node ID is exposed by cockroachdb metrics, we add it to ebpf_exporter
941+
// Node ID is exposed by cockroachdb metrics, let's add it to other exporters.
942+
if job != "cockroachdb" {
925943
labels["node_id"] = strconv.Itoa(nodeID)
926944
}
927945

pkg/roachprod/vm/startup.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ const (
3535
// EbpfExporterMetricsPath is the path that EbpfExporter serves metrics on.
3636
EbpfExporterMetricsPath = "/metrics"
3737

38+
// WorkloadMetricsPortMin and WorkloadMetricsPortMax are the range of ports
39+
// used by workload to expose metrics.
40+
WorkloadMetricsPortMin = 2112
41+
WorkloadMetricsPortMax = 2120
42+
// WorkloadMetricsPath is the path that workload serves metrics on.
43+
WorkloadMetricsPath = "/metrics"
44+
3845
// DefaultSharedUser is the default user that is shared across all VMs.
3946
DefaultSharedUser = "ubuntu"
4047
// InitializedFile is the base name of the initialization paths defined below.

0 commit comments

Comments
 (0)