Skip to content

Commit d69b673

Browse files
feat(HPA): Adds autoscaling config
OSC-1200 Signed-off-by: Dhruv Shah <dhruv.shah@sumologic.com>
1 parent cac352c commit d69b673

File tree

11 files changed

+299
-1
lines changed

11 files changed

+299
-1
lines changed

.changelog/4026.added.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
feat(HPA): Adds autoscaling config

deploy/helm/sumologic/README.md

Lines changed: 6 additions & 1 deletion
Large diffs are not rendered by default.

deploy/helm/sumologic/templates/instrumentation/otelcol-instrumentation/hpa.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ spec:
1616
name: {{ template "sumologic.metadata.name.otelcolinstrumentation.statefulset" . }}
1717
minReplicas: {{ $otelcolInstrumentation.autoscaling.minReplicas }}
1818
maxReplicas: {{ $otelcolInstrumentation.autoscaling.maxReplicas }}
19+
{{- if $otelcolInstrumentation.autoscaling.behavior }}
20+
behavior:
21+
{{- toYaml $otelcolInstrumentation.autoscaling.behavior | nindent 4 }}
22+
{{- end }}
1923
metrics:
2024
{{- if $otelcolInstrumentation.autoscaling.targetMemoryUtilizationPercentage }}
2125
- type: Resource

deploy/helm/sumologic/templates/instrumentation/traces-gateway/hpa.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ spec:
1616
name: {{ template "sumologic.metadata.name.tracesgateway.deployment" . }}
1717
minReplicas: {{ $tracesGateway.autoscaling.minReplicas }}
1818
maxReplicas: {{ $tracesGateway.autoscaling.maxReplicas }}
19+
{{- if $tracesGateway.autoscaling.behavior }}
20+
behavior:
21+
{{- toYaml $tracesGateway.autoscaling.behavior | nindent 4 }}
22+
{{- end }}
1923
metrics:
2024
{{- if $tracesGateway.autoscaling.targetMemoryUtilizationPercentage }}
2125
- type: Resource

deploy/helm/sumologic/templates/logs/common/hpa.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ spec:
1414
name: {{ template "sumologic.metadata.name.logs.statefulset" . }}
1515
minReplicas: {{ .Values.metadata.logs.autoscaling.minReplicas }}
1616
maxReplicas: {{ .Values.metadata.logs.autoscaling.maxReplicas }}
17+
{{- if .Values.metadata.logs.autoscaling.behavior }}
18+
behavior:
19+
{{- toYaml .Values.metadata.logs.autoscaling.behavior | nindent 4 }}
20+
{{- end }}
1721
metrics:
1822
{{- if .Values.metadata.logs.autoscaling.targetMemoryUtilizationPercentage }}
1923
- type: Resource

deploy/helm/sumologic/templates/metrics/common/hpa.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ spec:
1414
name: {{ template "sumologic.metadata.name.metrics.statefulset" . }}
1515
minReplicas: {{ .Values.metadata.metrics.autoscaling.minReplicas }}
1616
maxReplicas: {{ .Values.metadata.metrics.autoscaling.maxReplicas }}
17+
{{- if .Values.metadata.metrics.autoscaling.behavior }}
18+
behavior:
19+
{{- toYaml .Values.metadata.metrics.autoscaling.behavior | nindent 4 }}
20+
{{- end }}
1721
metrics:
1822
{{- if .Values.metadata.metrics.autoscaling.targetMemoryUtilizationPercentage }}
1923
- type: Resource

deploy/helm/sumologic/values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ sumologic:
518518
maxReplicas: 10
519519
targetCPUUtilizationPercentage: 70
520520
targetMemoryUtilizationPercentage: 70
521+
# behavior: {}
521522

522523
nodeSelector: {}
523524

@@ -1388,6 +1389,7 @@ otelcolInstrumentation:
13881389
maxReplicas: 10
13891390
targetCPUUtilizationPercentage: 100
13901391
# targetMemoryUtilizationPercentage: 50
1392+
# behavior: {}
13911393

13921394
statefulset:
13931395
nodeSelector: {}
@@ -1706,6 +1708,7 @@ metadata:
17061708
maxReplicas: 10
17071709
targetCPUUtilizationPercentage: 80
17081710
# targetMemoryUtilizationPercentage: 50
1711+
# behavior: {}
17091712

17101713
## Option to specify PodDisrutionBudgets
17111714
## You can specify only one of maxUnavailable and minAvailable in a single PodDisruptionBudget
@@ -1824,6 +1827,7 @@ metadata:
18241827
maxReplicas: 10
18251828
targetCPUUtilizationPercentage: 80
18261829
# targetMemoryUtilizationPercentage: 50
1830+
# behavior: {}
18271831

18281832
## Option to specify PodDisrutionBudgets
18291833
## You can specify only one of maxUnavailable and minAvailable in a single PodDisruptionBudget
@@ -1845,6 +1849,7 @@ tracesGateway:
18451849
maxReplicas: 10
18461850
targetCPUUtilizationPercentage: 100
18471851
# targetMemoryUtilizationPercentage: 50
1852+
# behavior: {}
18481853

18491854
deployment:
18501855
replicas: 1

tests/integration/features.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,31 @@ func GetMultipleMultilineLogsFeature() features.Feature {
683683
Feature()
684684
}
685685

686+
func GetHPAFeature(releaseName string) features.Feature {
687+
expectedHPA := []string{
688+
fmt.Sprintf("%s-sumologic-metrics", releaseName),
689+
fmt.Sprintf("%s-sumologic-otelcol-instrumentation", releaseName),
690+
fmt.Sprintf("%s-sumologic-otelcol-logs", releaseName),
691+
fmt.Sprintf("%s-sumologic-otelcol-metrics", releaseName),
692+
fmt.Sprintf("%s-sumologic-traces-gateway", releaseName),
693+
}
694+
expectedMetrics := map[string]map[string]int{}
695+
for _, hpa := range expectedHPA {
696+
expectedMetrics[hpa] = map[string]int{
697+
"cpu": 75,
698+
"memory": 75,
699+
}
700+
}
701+
return features.New("HPA").
702+
Assess("HPA configured", stepfuncs.WaitUntilHPAConfigured(
703+
expectedHPA,
704+
expectedMetrics,
705+
waitDuration,
706+
tickDuration,
707+
)).
708+
Feature()
709+
}
710+
686711
func GetEventsFeature() features.Feature {
687712
return features.New("events").
688713
Assess("events present", stepfuncs.WaitUntilExpectedLogsPresent(
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//go:build allversions
2+
// +build allversions
3+
4+
package integration
5+
6+
import (
7+
"testing"
8+
9+
strings_internal "github.com/SumoLogic/sumologic-kubernetes-collection/tests/integration/internal/strings"
10+
)
11+
12+
func Test_Helm_OT_HPA(t *testing.T) {
13+
installChecks := []featureCheck{
14+
CheckOtelcolMetadataLogsInstall,
15+
CheckOtelcolMetadataMetricsInstall,
16+
CheckOtelcolEventsInstall,
17+
CheckOtelcolMetricsCollectorInstall,
18+
CheckOtelcolLogsCollectorInstall,
19+
CheckTracesInstall,
20+
}
21+
22+
featInstall := GetInstallFeature(installChecks)
23+
24+
releaseName := strings_internal.ReleaseNameFromT(t)
25+
featHPA := GetHPAFeature(releaseName)
26+
27+
testenv.Test(t, featInstall, featHPA)
28+
}

tests/integration/internal/stepfuncs/assess_funcs.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"os"
78
"regexp"
89
"sort"
910
"strings"
@@ -12,6 +13,7 @@ import (
1213

1314
appsv1 "k8s.io/api/apps/v1"
1415
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16+
"k8s.io/client-go/kubernetes"
1517
log "k8s.io/klog/v2"
1618
"sigs.k8s.io/e2e-framework/klient/k8s"
1719
"sigs.k8s.io/e2e-framework/klient/k8s/resources"
@@ -351,6 +353,81 @@ func WaitUntilExpectedMetricLabelsPresent(
351353
}
352354
}
353355

356+
// WaitUntilHPAConfigured returns a features.Func that can be used in `Assess` calls.
357+
// It will wait until all the provided HPA are configured and active.
358+
func WaitUntilHPAConfigured(
359+
expectedHPAMetadata []string,
360+
expectedMetrics map[string]map[string]int,
361+
waitDuration time.Duration,
362+
tickDuration time.Duration,
363+
) features.Func {
364+
fmt.Println("Expected HPA is : ", expectedHPAMetadata, expectedMetrics)
365+
return WaitUntilHPAPresent(
366+
expectedHPAMetadata,
367+
expectedMetrics,
368+
waitDuration,
369+
tickDuration,
370+
)
371+
}
372+
373+
// WaitUntilHPAPresent returns a features.Func that can be used in `Assess` calls.
374+
// It will wait until all the provided HPA are configured and active. It will not verify the
375+
// functionality of the HPA.
376+
func WaitUntilHPAPresent(expectedHPAMetadata []string,
377+
expectedMetrics map[string]map[string]int,
378+
waitDuration time.Duration,
379+
tickDuration time.Duration,
380+
) features.Func {
381+
return func(ctx context.Context, t *testing.T, envConf *envconf.Config) context.Context {
382+
namespace := ctxopts.Namespace(ctx)
383+
if namespace == "" {
384+
log.Fatalf("Namespace not found in test context")
385+
}
386+
387+
cfg := envconf.New().WithKubeconfigFile(os.Getenv("KUBECONFIG"))
388+
c, err := kubernetes.NewForConfig(cfg.Client().RESTConfig())
389+
require.NoError(t, err)
390+
391+
assert.Eventually(t, func() bool {
392+
totalCount := len(expectedHPAMetadata)
393+
currCount := 0
394+
for _, expectedHPA := range expectedHPAMetadata {
395+
hpa, err := c.AutoscalingV2().HorizontalPodAutoscalers(namespace).
396+
Get(ctx, expectedHPA, metav1.GetOptions{})
397+
if err != nil {
398+
log.Errorf("failed to list HPAs: %v", err)
399+
return false
400+
}
401+
402+
if len(hpa.Spec.Metrics) >= 2 && hpa.Spec.Behavior.ScaleUp != nil &&
403+
hpa.Spec.Behavior.ScaleDown != nil {
404+
405+
resourceName1 := hpa.Spec.Metrics[0].Resource.Name
406+
val1 := hpa.Spec.Metrics[0].Resource.Target.AverageUtilization
407+
expectedVal1 := expectedMetrics[expectedHPA][string(resourceName1)]
408+
409+
resourceName2 := hpa.Spec.Metrics[0].Resource.Name
410+
val2 := hpa.Spec.Metrics[1].Resource.Target.AverageUtilization
411+
expectedVal2 := expectedMetrics[expectedHPA][string(resourceName2)]
412+
413+
if int(*val1) != expectedVal1 || int(*val2) != expectedVal2 {
414+
log.Infof("HPA %s is configured and active but expectedValue: [%d, %d] "+
415+
"did not match current value [%d, %d].",
416+
expectedHPA, expectedVal1, expectedVal2, int(*val1), int(*val2))
417+
return false
418+
}
419+
log.Infof("HPA %s is configured and active.", expectedHPA)
420+
currCount += 1
421+
}
422+
}
423+
log.Infof("Total HPA count: %d, Current HPA count: %d, expectedHPA: %v",
424+
totalCount, currCount, expectedHPAMetadata)
425+
return currCount == totalCount
426+
}, waitDuration, tickDuration)
427+
return ctx
428+
}
429+
}
430+
354431
// WaitUntilExpectedMetricsPresent returns a features.Func that can be used in `Assess` calls.
355432
// It will wait until the provided number of logs with the provided labels are returned by sumologic-mock's HTTP API on
356433
// the provided Service and port, until it succeeds or waitDuration passes.

0 commit comments

Comments
 (0)