Skip to content

Commit

Permalink
feat: Support CloudWatch as a metric provider (#1338)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryota Sakamoto <sakamo.ryota+github@gmail.com>
  • Loading branch information
ryota-sakamoto authored Sep 15, 2021
1 parent ebd6cbd commit 180b6fb
Show file tree
Hide file tree
Showing 18 changed files with 1,382 additions and 0 deletions.
140 changes: 140 additions & 0 deletions docs/analysis/cloudwatch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# CloudWatch Metrics

!!! important
Available since v1.1.0

A [CloudWatch](https://aws.amazon.com/cloudwatch/) using [GetMetricData](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricData.html) can be used to obtain measurements for analysis.

## Setup

You can use CloudWatch Metrics if you have used to EKS or not. This analysis is required IAM permission for `cloudwatch:GetMetricData` and you need to define `AWS_REGION` in Deployment for `argo-rollouts`.

### EKS

If you create new cluster on EKS, you can attach [cluster IAM role](https://docs.aws.amazon.com/eks/latest/userguide/service_IAM_role.html) or attach [IAM roles for service accounts](https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html).
If you have already cluster on EKS, you can attach [IAM roles for service accounts](https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html).

### not EKS

You need to define access key and secret key.

```yaml
apiVersion: v1
kind: Secret
metadata:
name: cloudwatch-secret
type: Opaque
stringData:
AWS_ACCESS_KEY_ID: <aws-access-key-id>
AWS_SECRET_ACCESS_KEY: <aws-secret-access-key>
AWS_REGION: <aws-region>
```
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: argo-rollouts
spec:
template:
spec:
containers:
- name: argo-rollouts
env:
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: cloudwatch-secret
key: AWS_ACCESS_KEY_ID
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: cloudwatch-secret
key: AWS_SECRET_ACCESS_KEY
- name: AWS_REGION
valueFrom:
secretKeyRef:
name: cloudwatch-secret
key: AWS_REGION
```
## Configuration
- `metricDataQueries` - GetMetricData query: [MetricDataQuery](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDataQuery.html)
- `interval` - optional interval, e.g. 30m, default: 5m

```yaml
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
name: success-rate
spec:
metrics:
- name: success-rate
interval: 1m
successCondition: "len(result[0].Values) >= 5 and all(result[0].Values, {# <= 0.01})"
failureLimit: 3
provider:
cloudWatch:
interval: 30m
metricDataQueries:
- {
"id": "rate",
"expression": "errors / requests"
}
- {
"id": "errors",
"metricStat": {
"metric": {
"namespace": "app",
"metricName": "errors"
},
"period": 300,
"stat": "Sum",
"unit": "Count"
},
"returnData": false
}
- {
"id": "requests",
"metricStat": {
"metric": {
"namespace": "app",
"metricName": "requests"
},
"period": 300,
"stat": "Sum",
"unit": "Count"
},
"returnData": false
}
```

## debug

You can confirm the results value in `AnalysisRun`.

```bash
$ kubectl get analysisrun/rollouts-name-xxxxxxxxxx-xx -o yaml
(snip)
status:
metricResults:
- count: 2
failed: 1
measurements:
- finishedAt: "2021-09-08T17:29:14Z"
phase: Failed
startedAt: "2021-09-08T17:29:13Z"
value: '[[0.0029476787030213707 0.006100422336931018 0.01020408163265306 0.007932573128408527
0.00589622641509434 0.006339144215530904]]'
- finishedAt: "2021-09-08T17:30:14Z"
phase: Successful
startedAt: "2021-09-08T17:30:14Z"
value: '[[0.004484304932735426 0.0058374494836102376 0.006736068585425597 0.008444444444444444
0.006859756097560976 0.0045385779122541605]]'
name: success-rate
phase: Running
successful: 1
phase: Running
startedAt: "2021-09-08T17:29:14Z"
```
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/argoproj/pkg v0.9.0
github.com/aws/aws-sdk-go-v2/config v1.0.0
github.com/aws/aws-sdk-go-v2/internal/ini v1.2.1 // indirect
github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.5.0
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.6.1
github.com/blang/semver v3.5.1+incompatible
github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ github.com/aws/aws-sdk-go v1.33.16/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZve
github.com/aws/aws-sdk-go v1.35.24/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/aws/aws-sdk-go-v2 v1.0.0/go.mod h1:smfAbmpW+tcRVuNUjo3MOArSZmW72t62rkCzc2i0TWM=
github.com/aws/aws-sdk-go-v2 v1.7.0/go.mod h1:tb9wi5s61kTDA5qCkcDbt3KRVV74GGslQkl/DRdX/P4=
github.com/aws/aws-sdk-go-v2 v1.8.1 h1:GcFgQl7MsBygmeeqXyV1ivrTEmsVz/rdFJaTcltG9ag=
github.com/aws/aws-sdk-go-v2 v1.8.1/go.mod h1:xEFuWz+3TYdlPRuo+CqATbeDWIWyaT5uAPwPaWtgse0=
github.com/aws/aws-sdk-go-v2/config v1.0.0 h1:x6vSFAwqAvhYPeSu60f0ZUlGHo3PKKmwDOTL8aMXtv4=
Expand All @@ -187,13 +188,16 @@ github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.0 h1:lO7fH5n7Q1dKcDBpuTmwJylD
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.0/go.mod h1:wpMHDCXvOXZxGCRSidyepa8uJHY4vaBGfY2/+oKU/Bc=
github.com/aws/aws-sdk-go-v2/internal/ini v1.2.1 h1:IkqRRUZTKaS16P2vpX+FNc2jq3JWa3c478gykQp4ow4=
github.com/aws/aws-sdk-go-v2/internal/ini v1.2.1/go.mod h1:Pv3WenDjI0v2Jl7UaMFIIbPOBbhn33RmmAmGgkXDoqY=
github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.5.0 h1:XO1uX7dQKWfD0WzycEfz+bL/7rl0SsQ05VJwLPWGzGM=
github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.5.0/go.mod h1:acH3+MQoiMzozT/ivU+DbRg7Ooo2298RdRaWcOv+4vM=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.6.1 h1:mGc8UvJS4XJv8Tp7Doxlx2p3vfwPx46K9zg+9s9szPE=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.6.1/go.mod h1:lGKz4aJbqGX+pgyXG47ZBAJPjwrlA5+TJsAuJ2+aE2g=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.0 h1:IAutMPSrynpvKOpHG6HyWHmh1xmxWAmYOK84NrQVqVQ=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.0/go.mod h1:3jExOmpbjgPnz2FJaMOfbSk1heTkZ66aD3yNtVhnjvI=
github.com/aws/aws-sdk-go-v2/service/sts v1.0.0 h1:6XCgxNfE4L/Fnq+InhVNd16DKc6Ue1f3dJl3IwwJRUQ=
github.com/aws/aws-sdk-go-v2/service/sts v1.0.0/go.mod h1:5f+cELGATgill5Pu3/vK3Ebuigstc+qYEHW5MvGWZO4=
github.com/aws/smithy-go v1.0.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw=
github.com/aws/smithy-go v1.5.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E=
github.com/aws/smithy-go v1.7.0 h1:+cLHMRrDZvQ4wk+KuQ9yH6eEg6KZEJ9RI2IkDqnygCg=
github.com/aws/smithy-go v1.7.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E=
github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod h1:q/89r3U2H7sSsE2t6Kca0lfwTK8JdoNGS/yzM/4iH5I=
Expand Down
53 changes: 53 additions & 0 deletions manifests/crds/analysis-run-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,59 @@ spec:
type: string
provider:
properties:
cloudWatch:
properties:
interval:
type: string
metricDataQueries:
items:
properties:
expression:
type: string
id:
type: string
label:
type: string
metricStat:
properties:
metric:
properties:
dimensions:
items:
properties:
name:
type: string
value:
type: string
type: object
type: array
metricName:
type: string
namespace:
type: string
type: object
period:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
stat:
type: string
unit:
type: string
type: object
period:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
returnData:
type: boolean
type: object
type: array
required:
- metricDataQueries
type: object
datadog:
properties:
interval:
Expand Down
53 changes: 53 additions & 0 deletions manifests/crds/analysis-template-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,59 @@ spec:
type: string
provider:
properties:
cloudWatch:
properties:
interval:
type: string
metricDataQueries:
items:
properties:
expression:
type: string
id:
type: string
label:
type: string
metricStat:
properties:
metric:
properties:
dimensions:
items:
properties:
name:
type: string
value:
type: string
type: object
type: array
metricName:
type: string
namespace:
type: string
type: object
period:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
stat:
type: string
unit:
type: string
type: object
period:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
returnData:
type: boolean
type: object
type: array
required:
- metricDataQueries
type: object
datadog:
properties:
interval:
Expand Down
53 changes: 53 additions & 0 deletions manifests/crds/cluster-analysis-template-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,59 @@ spec:
type: string
provider:
properties:
cloudWatch:
properties:
interval:
type: string
metricDataQueries:
items:
properties:
expression:
type: string
id:
type: string
label:
type: string
metricStat:
properties:
metric:
properties:
dimensions:
items:
properties:
name:
type: string
value:
type: string
type: object
type: array
metricName:
type: string
namespace:
type: string
type: object
period:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
stat:
type: string
unit:
type: string
type: object
period:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
returnData:
type: boolean
type: object
type: array
required:
- metricDataQueries
type: object
datadog:
properties:
interval:
Expand Down
Loading

0 comments on commit 180b6fb

Please sign in to comment.