Skip to content

Commit

Permalink
feat(cpuutil): support cpuutil also for deployments using loggregat…
Browse files Browse the repository at this point in the history
…or (#2808)
  • Loading branch information
geigerj0 authored Apr 2, 2024
1 parent b37669f commit 8b85c33
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ci/autoscaler/scripts/run-acceptance-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ cat > acceptance_config.json <<EOF
"use_http": false,
"service_name": "${deployment_name}",
"service_broker": "${deployment_name}",
"use_existing_organization": ${use_existing_organization},
"use_existing_organization": ${use_existing_organization},
"existing_organization": "${existing_organization}",
"use_existing_space": ${use_existing_space},
"existing_space": "${existing_space}",
Expand Down
1 change: 1 addition & 0 deletions src/acceptance/helpers/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func DebugInfo(cfg *config.Config, setup *workflowhelpers.ReproducibleTestSuiteS
commands = append(commands, command("cf", "autoscaling-metrics", anApp, "responsetime"))
commands = append(commands, command("cf", "autoscaling-metrics", anApp, "throughput"))
commands = append(commands, command("cf", "autoscaling-metrics", anApp, "cpu"))
commands = append(commands, command("cf", "autoscaling-metrics", anApp, "cpuutil"))
commands = append(commands, command("cf", "autoscaling-metrics", anApp, "test_metric"))
output := new(strings.Builder)
_, _ = fmt.Fprintf(output, "\n=============== DEBUG ===============\n")
Expand Down
5 changes: 3 additions & 2 deletions src/autoscaler/metricsgateway/nozzle.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func (n *Nozzle) filterEnvelopes(envelops []*loggregator_v2.Envelope) {
}

func isContainerMetricEnvelope(e *loggregator_v2.Envelope) bool {
_, exist := e.GetGauge().GetMetrics()["memory_quota"]
return exist
_, memoryQuotaExists := e.GetGauge().GetMetrics()["memory_quota"]
_, cpuEntitlementExists := e.GetGauge().GetMetrics()["cpu_entitlement"]
return memoryQuotaExists || cpuEntitlementExists
}
36 changes: 31 additions & 5 deletions src/autoscaler/metricsgateway/nozzle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var _ = Describe("Nozzle", func() {
},
}

containerMetricEnvelope = loggregator_v2.Envelope{
containerMetricEnvelope1 = loggregator_v2.Envelope{
SourceId: testAppId,
Message: &loggregator_v2.Envelope_Gauge{
Gauge: &loggregator_v2.Gauge{
Expand All @@ -72,6 +72,21 @@ var _ = Describe("Nozzle", func() {
},
}

// cpu_entitlement is emitted in a separate envelope https://docs.cloudfoundry.org/loggregator/container-metrics.html
containerMetricEnvelope2 = loggregator_v2.Envelope{
SourceId: testAppId,
Message: &loggregator_v2.Envelope_Gauge{
Gauge: &loggregator_v2.Gauge{
Metrics: map[string]*loggregator_v2.GaugeValue{
"cpu_entitlement": {
Unit: "percentage",
Value: 20.5,
},
},
},
},
}

customMetricEnvelope = loggregator_v2.Envelope{
SourceId: testAppId,
DeprecatedTags: map[string]*loggregator_v2.Value{
Expand Down Expand Up @@ -164,8 +179,7 @@ var _ = Describe("Nozzle", func() {
return appIDs
}
envelopes = []*loggregator_v2.Envelope{
&containerMetricEnvelope,
&httpStartStopEnvelope,
&containerMetricEnvelope1,
}
LogServerName = "reverselogproxy"

Expand Down Expand Up @@ -226,10 +240,22 @@ var _ = Describe("Nozzle", func() {
Consistently(envelopChan).ShouldNot(Receive())
})
})
Context("there is container metric envelope", func() {
Context("there is container metric envelope 1", func() {
BeforeEach(func() {
envelopes = []*loggregator_v2.Envelope{
&containerMetricEnvelope1,
}
})
It("should accept the envelope", func() {
Eventually(envelopChan).Should(Receive())

})
})

Context("there is container metric envelope 2", func() {
BeforeEach(func() {
envelopes = []*loggregator_v2.Envelope{
&containerMetricEnvelope,
&containerMetricEnvelope2,
}
})
It("should accept the envelope", func() {
Expand Down

0 comments on commit 8b85c33

Please sign in to comment.