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

Support OSM progressive traffic shifting in Flagger #955

Merged
merged 1 commit into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- traefik
- gloo
- skipper
- osm
- kubernetes
steps:
- name: Checkout
Expand Down
42 changes: 42 additions & 0 deletions artifacts/examples/osm-canary-steps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
name: podinfo
namespace: test
spec:
provider: osm
targetRef:
apiVersion: apps/v1
kind: Deployment
name: podinfo
progressDeadlineSeconds: 600
service:
port: 9898
targetPort: 9898
analysis:
interval: 15s
threshold: 10
stepWeights: [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]
metrics:
- name: request-success-rate
thresholdRange:
min: 99
interval: 1m
- name: request-duration
thresholdRange:
max: 500
interval: 30s
webhooks:
- name: acceptance-test
type: pre-rollout
url: http://flagger-loadtester.test/
timeout: 15s
metadata:
type: bash
cmd: "curl -sd 'test' http://podinfo-canary.test:9898/token | grep token"
- name: load-test
type: rollout
url: http://flagger-loadtester.test/
timeout: 5s
metadata:
cmd: "hey -z 1m -q 10 -c 2 http://podinfo-canary.test:9898/"
43 changes: 43 additions & 0 deletions artifacts/examples/osm-canary.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
name: podinfo
namespace: test
spec:
provider: osm
targetRef:
apiVersion: apps/v1
kind: Deployment
name: podinfo
progressDeadlineSeconds: 600
service:
port: 9898
targetPort: 9898
analysis:
interval: 15s
threshold: 10
maxWeight: 50
stepWeight: 5
metrics:
- name: request-success-rate
thresholdRange:
min: 99
interval: 1m
- name: request-duration
thresholdRange:
max: 500
interval: 30s
webhooks:
- name: acceptance-test
type: pre-rollout
url: http://flagger-loadtester.test/
timeout: 15s
metadata:
type: bash
cmd: "curl -sd 'test' http://podinfo-canary.test:9898/token | grep token"
- name: load-test
type: rollout
url: http://flagger-loadtester.test/
timeout: 5s
metadata:
cmd: "hey -z 1m -q 10 -c 2 http://podinfo-canary.test:9898/"
2 changes: 2 additions & 0 deletions charts/flagger/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ keywords:
- contour
- nginx
- traefik
- osm
- smi
- gitops
- canary
2 changes: 1 addition & 1 deletion charts/flagger/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ podPriorityClassName: ""

metricsServer: "http://prometheus:9090"

# accepted values are kubernetes, istio, linkerd, appmesh, contour, nginx, gloo, skipper, traefik
# accepted values are kubernetes, istio, linkerd, appmesh, contour, nginx, gloo, skipper, traefik, osm
meshProvider: ""

# single namespace restriction
Expand Down
2 changes: 2 additions & 0 deletions charts/loadtester/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ keywords:
- appmesh
- linkerd
- gloo
- osm
- smi
- gitops
- load testing
1 change: 1 addition & 0 deletions charts/loadtester/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ spec:
app.kubernetes.io/name: {{ include "loadtester.name" . }}
annotations:
appmesh.k8s.aws/ports: "444"
openservicemesh.io/inbound-port-exclusion-list: "80, 8080"
johnsonshi marked this conversation as resolved.
Show resolved Hide resolved
{{- if .Values.podAnnotations }}
{{ toYaml .Values.podAnnotations | indent 8 }}
{{- end }}
Expand Down
1 change: 1 addition & 0 deletions charts/podinfo/templates/tests/jwt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ metadata:
sidecar.istio.io/inject: "false"
linkerd.io/inject: disabled
appmesh.k8s.aws/sidecarInjectorWebhook: disabled
openservicemesh.io/sidecar-injection: disabled
spec:
containers:
- name: tools
Expand Down
2 changes: 1 addition & 1 deletion cmd/flagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func init() {
flag.BoolVar(&zapReplaceGlobals, "zap-replace-globals", false, "Whether to change the logging level of the global zap logger.")
flag.StringVar(&zapEncoding, "zap-encoding", "json", "Zap logger encoding.")
flag.StringVar(&namespace, "namespace", "", "Namespace that flagger would watch canary object.")
flag.StringVar(&meshProvider, "mesh-provider", "istio", "Service mesh provider, can be istio, linkerd, appmesh, contour, gloo, nginx, skipper or traefik.")
flag.StringVar(&meshProvider, "mesh-provider", "istio", "Service mesh provider, can be istio, linkerd, appmesh, contour, gloo, nginx, skipper, traefik or osm.")
flag.StringVar(&selectorLabels, "selector-labels", "app,name,app.kubernetes.io/name", "List of pod labels that Flagger uses to create pod selectors.")
flag.StringVar(&ingressAnnotationsPrefix, "ingress-annotations-prefix", "nginx.ingress.kubernetes.io", "Annotations prefix for NGINX ingresses.")
flag.StringVar(&ingressClass, "ingress-class", "", "Ingress class used for annotating HTTPProxy objects.")
Expand Down
5 changes: 5 additions & 0 deletions kustomize/osm/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace: osm-system
bases:
- ../base/flagger/
patchesStrategicMerge:
- patch.yaml
27 changes: 27 additions & 0 deletions kustomize/osm/patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: flagger
spec:
template:
spec:
containers:
- name: flagger
args:
- -log-level=info
- -include-label-prefix=app.kubernetes.io
- -mesh-provider=osm
- -metrics-server=http://osm-prometheus.osm-system.svc:7070
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: flagger
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: flagger
subjects:
- kind: ServiceAccount
name: flagger
namespace: osm-system
1 change: 1 addition & 0 deletions kustomize/tester/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ spec:
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8080"
openservicemesh.io/inbound-port-exclusion-list: "80, 8080"
spec:
containers:
- name: loadtester
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/flagger/v1beta1/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ const (
KubernetesProvider string = "kubernetes"
SkipperProvider string = "skipper"
TraefikProvider string = "traefik"
OsmProvider string = "osm"
)
4 changes: 4 additions & 0 deletions pkg/metrics/observers/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func (factory Factory) Observer(provider string) Interface {
return &TraefikObserver{
client: factory.Client,
}
case provider == flaggerv1.OsmProvider:
return &OsmObserver{
client: factory.Client,
}
default:
return &IstioObserver{
client: factory.Client,
Expand Down
96 changes: 96 additions & 0 deletions pkg/metrics/observers/osm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
Copyright 2021 The Flux authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package observers

import (
"fmt"
"time"

flaggerv1 "github.com/fluxcd/flagger/pkg/apis/flagger/v1beta1"
"github.com/fluxcd/flagger/pkg/metrics/providers"
)

var osmQueries = map[string]string{
"request-success-rate": `
sum(
rate(
osm_request_total{
destination_namespace="{{ namespace }}",
destination_kind="Deployment",
destination_name="{{ target }}",
response_code!~"5.*"
}[{{ interval }}]
)
)
/
sum(
rate(
osm_request_total{
destination_namespace="{{ namespace }}",
destination_kind="Deployment",
destination_name="{{ target }}"
}[{{ interval }}]
)
)
* 100`,
"request-duration": `
histogram_quantile(
0.99,
sum(
rate(
osm_request_duration_ms_bucket{
destination_namespace="{{ namespace }}",
destination_kind="Deployment",
destination_name="{{ target }}"
}[{{ interval }}]
)
) by (le)
)`,
}

type OsmObserver struct {
client providers.Interface
}

func (ob *OsmObserver) GetRequestSuccessRate(model flaggerv1.MetricTemplateModel) (float64, error) {
query, err := RenderQuery(osmQueries["request-success-rate"], model)
if err != nil {
return 0, fmt.Errorf("rendering query failed: %w", err)
}

value, err := ob.client.RunQuery(query)
if err != nil {
return 0, fmt.Errorf("running query failed: %w", err)
}

return value, nil
}

func (ob *OsmObserver) GetRequestDuration(model flaggerv1.MetricTemplateModel) (time.Duration, error) {
query, err := RenderQuery(osmQueries["request-duration"], model)
if err != nil {
return 0, fmt.Errorf("rendering query failed: %w", err)
}

value, err := ob.client.RunQuery(query)
if err != nil {
return 0, fmt.Errorf("running query failed: %w", err)
}

ms := time.Duration(int64(value)) * time.Millisecond
return ms, nil
}
Loading