CloudWatch 메트릭 (CloudWatch Metrics)
Argo Rollouts에서 CloudWatch의 GetMetricData를 사용해 분석용 측정값을 얻는 방법을 설명해 드릴게요. EKS 여부에 따른 IAM 설정부터 metricDataQueries 구성 방법, 결과 확인까지 옆에서 차근차근 설명할게요.
출처: 문서
본문
Important
v1.1.0부터 사용할 수 있어요.
GetMetricData를 사용하는 CloudWatch를 이용해서 분석을 위한 측정값을 얻을 수 있어요.
설정 (Setup)
EKS를 사용했든 아니든 CloudWatch Metrics를 사용할 수 있어요. 이 분석에는 cloudwatch:GetMetricData에 대한 IAM 권한이 필요하고, argo-rollouts Deployment에 AWS_REGION을 정의해야 해요.
EKS
EKS에 새 클러스터를 만들었다면 cluster IAM role을 연결하거나 service account용 IAM roles을 연결할 수 있어요. EKS에 이미 클러스터가 있다면 service account용 IAM roles를 연결할 수 있어요.
EKS가 아닌 경우
access key와 secret key를 정의해야 해요.
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>
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 쿼리: MetricDataQuery -
interval- 선택적 interval, 예: 30m, 기본값: 5m
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)
AnalysisRun에서 결과 값을 확인할 수 있어요.
$ 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"