Skip to content

Commit

Permalink
Ingester: Defer converting from LabelPairs to Metric until flush (gra…
Browse files Browse the repository at this point in the history
…fana#997)

* Defer converting from LabelPairs to Metric until needed

Since we average hundreds of samples to a chunk, it saves a lot of
work to leave label name/value sets as the slice they come in as,
rather than converting to the map type that Prometheus uses.

They are converted on flush, to avoid changing the chunk store.

* Store labelPairs in series sorted, for faster lookup
* Extract BenchmarkMetric as re-usable fixture for tests
* Add benchmark for Ingester Push()
* Copy name/value bytes, to avoid keeping the gRPC buffer alive
  • Loading branch information
bboreham authored Sep 13, 2018
1 parent 13d488b commit 8d8a668
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
21 changes: 1 addition & 20 deletions chunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,26 +198,7 @@ func TestChunksToMatrix(t *testing.T) {
}

func benchmarkChunk(now model.Time) Chunk {
// This is a real example from Kubernetes' embedded cAdvisor metrics, lightly obfuscated
return dummyChunkFor(now, model.Metric{
model.MetricNameLabel: "container_cpu_usage_seconds_total",
"beta_kubernetes_io_arch": "amd64",
"beta_kubernetes_io_instance_type": "c3.somesize",
"beta_kubernetes_io_os": "linux",
"container_name": "some-name",
"cpu": "cpu01",
"failure_domain_beta_kubernetes_io_region": "somewhere-1",
"failure_domain_beta_kubernetes_io_zone": "somewhere-1b",
"id": "/kubepods/burstable/pod6e91c467-e4c5-11e7-ace3-0a97ed59c75e/a3c8498918bd6866349fed5a6f8c643b77c91836427fb6327913276ebc6bde28",
"image": "registry/organisation/name@sha256:dca3d877a80008b45d71d7edc4fd2e44c0c8c8e7102ba5cbabec63a374d1d506",
"instance": "ip-111-11-1-11.ec2.internal",
"job": "kubernetes-cadvisor",
"kubernetes_io_hostname": "ip-111-11-1-11",
"monitor": "prod",
"name": "k8s_some-name_some-other-name-5j8s8_kube-system_6e91c467-e4c5-11e7-ace3-0a97ed59c75e_0",
"namespace": "kube-system",
"pod_name": "some-other-name-5j8s8",
})
return dummyChunkFor(now, BenchmarkMetric)
}

func BenchmarkEncode(b *testing.B) {
Expand Down
24 changes: 24 additions & 0 deletions fixtures.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package chunk

import "github.com/prometheus/common/model"

// BenchmarkMetric is a real example from Kubernetes' embedded cAdvisor metrics, lightly obfuscated
var BenchmarkMetric = model.Metric{
model.MetricNameLabel: "container_cpu_usage_seconds_total",
"beta_kubernetes_io_arch": "amd64",
"beta_kubernetes_io_instance_type": "c3.somesize",
"beta_kubernetes_io_os": "linux",
"container_name": "some-name",
"cpu": "cpu01",
"failure_domain_beta_kubernetes_io_region": "somewhere-1",
"failure_domain_beta_kubernetes_io_zone": "somewhere-1b",
"id": "/kubepods/burstable/pod6e91c467-e4c5-11e7-ace3-0a97ed59c75e/a3c8498918bd6866349fed5a6f8c643b77c91836427fb6327913276ebc6bde28",
"image": "registry/organisation/name@sha256:dca3d877a80008b45d71d7edc4fd2e44c0c8c8e7102ba5cbabec63a374d1d506",
"instance": "ip-111-11-1-11.ec2.internal",
"job": "kubernetes-cadvisor",
"kubernetes_io_hostname": "ip-111-11-1-11",
"monitor": "prod",
"name": "k8s_some-name_some-other-name-5j8s8_kube-system_6e91c467-e4c5-11e7-ace3-0a97ed59c75e_0",
"namespace": "kube-system",
"pod_name": "some-other-name-5j8s8",
}

0 comments on commit 8d8a668

Please sign in to comment.