Skip to content

Commit

Permalink
Added auto-scale to the collector
Browse files Browse the repository at this point in the history
A Horizontal Pod Autoscaler (HPA) was added in this PR, along with a new MinReplicas and MaxReplicas. With that, the collector should now automatically scale up and down based on the CPU and/or memory consumption. When none of the new properties are specified, the minimum amount of replicas is 1, while the maximum number of replicas is 100. The HPA configuration is added only when the deployment strategy is either production or streaming.

Signed-off-by: Juraci Paixão Kröhling <[email protected]>
  • Loading branch information
jpkrohling committed Jan 17, 2020
1 parent 1c151cb commit 5040bbf
Show file tree
Hide file tree
Showing 18 changed files with 755 additions and 34 deletions.
14 changes: 14 additions & 0 deletions deploy/crds/jaegertracing.io_jaegers_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5310,12 +5310,26 @@ spec:
additionalProperties:
type: string
type: object
autoscale:
description: Autoscale turns on/off the autoscalign feature. By
default, it's enabled if the Replicas field is not set.
type: boolean
image:
type: string
labels:
additionalProperties:
type: string
type: object
maxReplicas:
description: MaxReplicas sets an upper bound to the autoscaling
feature. When autoscaling is enabled and no value is provided,
a default value is used.
format: int32
type: integer
minReplicas:
description: MinReplicas sets a lower bound to the autoscaling feature.
format: int32
type: integer
options:
description: Options defines a common options parameter to the different
structs
Expand Down
41 changes: 41 additions & 0 deletions deploy/examples/tracegen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# this is a deployment for the tracegen utility that is delivered with Jaeger
# use with care, as it generates quite some load in the current setting
# this deployment was especially designed to test the autoscaling capabilities
# and requires an instance named 'simple-prod'.
apiVersion: apps/v1
kind: Deployment
metadata:
name: tracegen
annotations:
"sidecar.jaegertracing.io/inject": "simple-prod"
spec:
replicas: 10
selector:
matchLabels:
app: tracegen
template:
metadata:
labels:
app: tracegen
spec:
containers:
- name: tracegen
image: jaegertracing/jaeger-tracegen:latest
args:
- -duration=30m
- -workers=10
- name: jaeger-agent
image: jaegertracing/jaeger-agent:1.16.0
args:
- --reporter.grpc.host-port=dns:///simple-prod-collector-headless.default:14250
- --reporter.type=grpc
env:
- name: POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
ports:
- containerPort: 6831
name: jg-compact-trft
protocol: UDP
12 changes: 12 additions & 0 deletions pkg/apis/jaegertracing/v1/jaeger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,22 @@ type JaegerAllInOneSpec struct {
// JaegerCollectorSpec defines the options to be used when deploying the collector
// +k8s:openapi-gen=true
type JaegerCollectorSpec struct {
// Autoscale turns on/off the autoscalign feature. By default, it's enabled if the Replicas field is not set.
// +optional
Autoscale *bool `json:"autoscale,omitempty"`

// Replicas represents the number of replicas to create for this service.
// +optional
Replicas *int32 `json:"replicas,omitempty"`

// MinReplicas sets a lower bound to the autoscaling feature.
// +optional
MinReplicas *int32 `json:"minReplicas,omitempty"`

// MaxReplicas sets an upper bound to the autoscaling feature. When autoscaling is enabled and no value is provided, a default value is used.
// +optional
MaxReplicas *int32 `json:"maxReplicas,omitempty"`

// +optional
Image string `json:"image,omitempty"`

Expand Down
15 changes: 15 additions & 0 deletions pkg/apis/jaegertracing/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions pkg/apis/jaegertracing/v1/zz_generated.openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,34 @@ func schema_pkg_apis_jaegertracing_v1_JaegerCollectorSpec(ref common.ReferenceCa
Description: "JaegerCollectorSpec defines the options to be used when deploying the collector",
Type: []string{"object"},
Properties: map[string]spec.Schema{
"autoscale": {
SchemaProps: spec.SchemaProps{
Description: "Autoscale turns on/off the autoscalign feature. By default, it's enabled if the Replicas field is not set.",
Type: []string{"boolean"},
Format: "",
},
},
"replicas": {
SchemaProps: spec.SchemaProps{
Description: "Replicas represents the number of replicas to create for this service.",
Type: []string{"integer"},
Format: "int32",
},
},
"minReplicas": {
SchemaProps: spec.SchemaProps{
Description: "MinReplicas sets a lower bound to the autoscaling feature.",
Type: []string{"integer"},
Format: "int32",
},
},
"maxReplicas": {
SchemaProps: spec.SchemaProps{
Description: "MaxReplicas sets an upper bound to the autoscaling feature. When autoscaling is enabled and no value is provided, a default value is used.",
Type: []string{"integer"},
Format: "int32",
},
},
"image": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Expand Down
65 changes: 65 additions & 0 deletions pkg/controller/jaeger/horizontalpodautoscaler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package jaeger

import (
"context"

log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/global"
autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2"
"sigs.k8s.io/controller-runtime/pkg/client"

v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
"github.com/jaegertracing/jaeger-operator/pkg/inventory"
"github.com/jaegertracing/jaeger-operator/pkg/tracing"
)

func (r *ReconcileJaeger) applyHorizontalPodAutoscalers(ctx context.Context, jaeger v1.Jaeger, desired []autoscalingv2beta2.HorizontalPodAutoscaler) error {
tracer := global.TraceProvider().GetTracer(v1.ReconciliationTracer)
ctx, span := tracer.Start(ctx, "applyHorizontalPodAutoscalers")
defer span.End()

opts := []client.ListOption{
client.InNamespace(jaeger.Namespace),
client.MatchingLabels(map[string]string{
"app.kubernetes.io/instance": jaeger.Name,
"app.kubernetes.io/managed-by": "jaeger-operator",
}),
}
hpaList := &autoscalingv2beta2.HorizontalPodAutoscalerList{}
if err := r.client.List(ctx, hpaList, opts...); err != nil {
return tracing.HandleError(err, span)
}

hpaInventory := inventory.ForHorizontalPodAutoscalers(hpaList.Items, desired)
for _, d := range hpaInventory.Create {
jaeger.Logger().WithFields(log.Fields{
"hpa": d.Name,
"namespace": d.Namespace,
}).Debug("creating hpa")
if err := r.client.Create(ctx, &d); err != nil {
return tracing.HandleError(err, span)
}
}

for _, d := range hpaInventory.Update {
jaeger.Logger().WithFields(log.Fields{
"hpa": d.Name,
"namespace": d.Namespace,
}).Debug("updating hpa")
if err := r.client.Update(ctx, &d); err != nil {
return tracing.HandleError(err, span)
}
}

for _, d := range hpaInventory.Delete {
jaeger.Logger().WithFields(log.Fields{
"hpa": d.Name,
"namespace": d.Namespace,
}).Debug("deleting hpa")
if err := r.client.Delete(ctx, &d); err != nil {
return tracing.HandleError(err, span)
}
}

return nil
}
Loading

0 comments on commit 5040bbf

Please sign in to comment.