Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added auto-scale to the collector #856

Merged
merged 3 commits into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 autoscale feature. By default,
jpkrohling marked this conversation as resolved.
Show resolved Hide resolved
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.
jpkrohling marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't tracegen image be versioned inline with the other jaeger components?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, opened an issue (#866) to track this. The first image will probably be 1.17 (next release).

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 autoscale 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 autoscale 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