Skip to content

Commit

Permalink
Add additional metadata to metrics (kube-burner#253)
Browse files Browse the repository at this point in the history
- Add JobConfig metadata

To Do :
- Add Extra Metadata from ocp wrapper

Note: Ignore JobConfig.Objects

Signed-off-by: Joe Talerico <[email protected]>
  • Loading branch information
jtaleric authored Feb 17, 2023
1 parent df552e0 commit 3635a48
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 20 deletions.
1 change: 1 addition & 0 deletions pkg/burner/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func Run(configSpec config.Spec, uuid string, p *prometheus.Prometheus, alertM *
}
jobList[jobPosition].End = time.Now().UTC()
prometheusJob.End = jobList[jobPosition].End
prometheusJob.JobConfig = job.Config
elapsedTime := prometheusJob.End.Sub(prometheusJob.Start).Seconds()
// Don't append to Prometheus jobList when prometheus it's not initialized
if p != nil {
Expand Down
22 changes: 12 additions & 10 deletions pkg/measurements/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@ import (
"time"

"github.com/cloud-bulldozer/kube-burner/log"
"github.com/cloud-bulldozer/kube-burner/pkg/config"
"github.com/cloud-bulldozer/kube-burner/pkg/measurements/types"
)

// LatencyQuantiles holds the latency measurement quantiles
type LatencyQuantiles struct {
QuantileName string `json:"quantileName"`
UUID string `json:"uuid"`
P99 int `json:"P99"`
P95 int `json:"P95"`
P50 int `json:"P50"`
Max int `json:"max"`
Avg int `json:"avg"`
Timestamp time.Time `json:"timestamp"`
MetricName string `json:"metricName"`
JobName string `json:"jobName"`
QuantileName string `json:"quantileName"`
UUID string `json:"uuid"`
P99 int `json:"P99"`
P95 int `json:"P95"`
P50 int `json:"P50"`
Max int `json:"max"`
Avg int `json:"avg"`
Timestamp time.Time `json:"timestamp"`
MetricName string `json:"metricName"`
JobName string `json:"jobName"`
JobConfig config.Job `json:"jobConfig"`
}

// SetQuantile adds quantile value
Expand Down
22 changes: 15 additions & 7 deletions pkg/measurements/pod_latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"github.com/cloud-bulldozer/kube-burner/log"
"github.com/cloud-bulldozer/kube-burner/pkg/config"
"github.com/cloud-bulldozer/kube-burner/pkg/measurements/metrics"
"github.com/cloud-bulldozer/kube-burner/pkg/measurements/types"
v1 "k8s.io/api/core/v1"
Expand All @@ -44,13 +45,14 @@ type podMetric struct {
containersReady time.Time
ContainersReadyLatency int `json:"containersReadyLatency"`
podReady time.Time
PodReadyLatency int `json:"podReadyLatency"`
MetricName string `json:"metricName"`
JobName string `json:"jobName"`
UUID string `json:"uuid"`
Namespace string `json:"namespace"`
Name string `json:"podName"`
NodeName string `json:"nodeName"`
PodReadyLatency int `json:"podReadyLatency"`
MetricName string `json:"metricName"`
JobName string `json:"jobName"`
JobConfig config.Job `json:"jobConfig"`
UUID string `json:"uuid"`
Namespace string `json:"namespace"`
Name string `json:"podName"`
NodeName string `json:"nodeName"`
}

type podLatency struct {
Expand All @@ -68,6 +70,8 @@ func init() {
func (p *podLatency) handleCreatePod(obj interface{}) {
now := time.Now().UTC()
pod := obj.(*v1.Pod)
jc := factory.jobConfig
jc.Objects = nil // metric doesn't need this data
if _, exists := p.metrics[string(pod.UID)]; !exists {
if strings.Contains(pod.Namespace, factory.jobConfig.Namespace) {
p.metrics[string(pod.UID)] = podMetric{
Expand All @@ -76,6 +80,7 @@ func (p *podLatency) handleCreatePod(obj interface{}) {
Name: pod.Name,
MetricName: podLatencyMeasurement,
UUID: factory.uuid,
JobConfig: *jc,
JobName: factory.jobConfig.Name,
}
}
Expand Down Expand Up @@ -208,6 +213,8 @@ func (p *podLatency) normalizeMetrics() {
func (p *podLatency) calcQuantiles() {
quantiles := []float64{0.5, 0.95, 0.99}
quantileMap := map[v1.PodConditionType][]int{}
jc := factory.jobConfig
jc.Objects = nil
for _, normLatency := range p.normLatencies {
quantileMap[v1.PodScheduled] = append(quantileMap[v1.PodScheduled], normLatency.(podMetric).SchedulingLatency)
quantileMap[v1.ContainersReady] = append(quantileMap[v1.ContainersReady], normLatency.(podMetric).ContainersReadyLatency)
Expand All @@ -220,6 +227,7 @@ func (p *podLatency) calcQuantiles() {
UUID: factory.uuid,
Timestamp: time.Now().UTC(),
JobName: factory.jobConfig.Name,
JobConfig: *jc,
MetricName: podLatencyQuantilesMeasurement,
}
sort.Ints(v)
Expand Down
8 changes: 8 additions & 0 deletions pkg/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func (p *Prometheus) ScrapeJobsMetrics(indexer *indexers.Indexer) error {

func (p *Prometheus) parseVector(metricName, query string, value model.Value, metrics *[]interface{}) error {
var jobName string
var jobConfig config.Job
data, ok := value.(model.Vector)
if !ok {
return fmt.Errorf("unsupported result format: %s", value.Type().String())
Expand All @@ -183,6 +184,8 @@ func (p *Prometheus) parseVector(metricName, query string, value model.Value, me
for _, prometheusJob := range p.JobList {
if v.Timestamp.Time().Before(prometheusJob.End) {
jobName = prometheusJob.Name
jobConfig = prometheusJob.JobConfig
jobConfig.Objects = nil // no need to insert this into the metric.
}
}
m := metric{
Expand All @@ -191,6 +194,7 @@ func (p *Prometheus) parseVector(metricName, query string, value model.Value, me
Query: query,
MetricName: metricName,
JobName: jobName,
JobConfig: jobConfig,
}
for k, v := range v.Metric {
if k == "__name__" {
Expand All @@ -211,6 +215,7 @@ func (p *Prometheus) parseVector(metricName, query string, value model.Value, me

func (p *Prometheus) parseMatrix(metricName, query string, value model.Value, metrics *[]interface{}) error {
var jobName string
var jobConfig config.Job
data, ok := value.(model.Matrix)
if !ok {
return fmt.Errorf("unsupported result format: %s", value.Type().String())
Expand All @@ -220,6 +225,8 @@ func (p *Prometheus) parseMatrix(metricName, query string, value model.Value, me
for _, job := range p.JobList {
if val.Timestamp.Time().Before(job.End) {
jobName = job.Name
jobConfig = job.JobConfig
jobConfig.Objects = nil // no need to insert this into the metric.
}
}
m := metric{
Expand All @@ -228,6 +235,7 @@ func (p *Prometheus) parseMatrix(metricName, query string, value model.Value, me
Query: query,
MetricName: metricName,
JobName: jobName,
JobConfig: jobConfig,
Timestamp: val.Timestamp.Time(),
}
for k, v := range v.Metric {
Expand Down
8 changes: 5 additions & 3 deletions pkg/prometheus/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ type Prometheus struct {
}

type Job struct {
Start time.Time
End time.Time
Name string
Start time.Time
End time.Time
Name string
JobConfig config.Job
}

// This object implements RoundTripper
Expand All @@ -62,4 +63,5 @@ type metric struct {
Query string `json:"query"`
MetricName string `json:"metricName,omitempty"`
JobName string `json:"jobName,omitempty"`
JobConfig config.Job `json:"jobConfig,omitempty"`
}

0 comments on commit 3635a48

Please sign in to comment.