Web 메트릭 (Web Metrics)
외부 서비스로 HTTP 요청을 보내 측정값을 얻는 분석 방법이에요. 웹훅(webhook)처럼 동작하며, 반환되는 JSON 응답을 필요한 값으로 파싱해 canary 배포의 성공 여부를 판단할 수 있습니다.
출처: Argo Rollouts 문서
본문
외부 서비스에 HTTP 요청을 보내 측정값을 얻을 수 있습니다. 이 예시는 특정 URL에 HTTP GET 요청을 수행합니다. 웹훅 응답은 반드시 JSON 콘텐츠를 반환해야 해요. 선택적인 jsonPath 표현식의 결과는 result 변수에 할당되며, 이 변수는 successCondition과 failureCondition 표현식에서 참조할 수 있습니다. jsonPath를 생략하면 응답 본문 전체가 결과 변수로 사용됩니다.
metrics:
- name: webmetric
successCondition: result == true
provider:
web:
url: "http://my-server.com/api/v1/measurement?service={{ args.service-name }}"
timeoutSeconds: 20 # defaults to 10 seconds
headers:
- key: Authorization
value: "Bearer {{ args.api-token }}"
jsonPath: "{$.data.ok}"
다음 예시에서는, 주어진 페이로드를 기준으로 data.ok 필드가 true이고 data.successPercent가 0.90보다 크면 측정값은 성공(Successful)으로 판정됩니다.
{
"data": {
"ok": true,
"successPercent": 0.95
}
}
metrics:
- name: webmetric
successCondition: "result.ok && result.successPercent >= 0.90"
provider:
web:
url: "http://my-server.com/api/v1/measurement?service={{ args.service-name }}"
headers:
- key: Authorization
value: "Bearer {{ args.api-token }}"
jsonPath: "{$.data}"
참고: 결과가 문자열인 경우, asInt와 asFloat 두 개의 편의 함수를 사용해 결과값을 숫자 타입으로 변환할 수 있어요. 그래야 수학적 비교 연산자(예: >, <, >=, <=)를 사용할 수 있습니다.
선택적인 Web 메서드 (Optional web methods)
method 필드와 body 또는 jsonBody 필드를 지정하면 POST나 PUT 요청을 사용할 수 있습니다.
metrics:
- name: webmetric
successCondition: result == true
provider:
web:
method: POST # valid values are GET|POST|PUT, defaults to GET
url: "http://my-server.com/api/v1/measurement?service={{ args.service-name }}"
timeoutSeconds: 20 # defaults to 10 seconds
headers:
- key: Authorization
value: "Bearer {{ args.api-token }}"
- key: Content-Type # if body is a json, it is recommended to set the Content-Type
value: "application/json"
body: "string value"
jsonPath: "{$.data.ok}"
!!! tip
JSON을 전송하려면 jsonBody를 사용할 수 있으며 Content-Type은 자동으로 json으로 설정됩니다. GET 요청에 body나 jsonBody 필드를 설정하면 오류가 발생합니다. body 또는 jsonBody 중 하나만 설정해야 하며, 둘 다 설정하면 오류가 발생합니다.
metrics:
- name: webmetric
successCondition: result == true
provider:
web:
method: POST # valid values are GET|POST|PUT, defaults to GET
url: "http://my-server.com/api/v1/measurement?service={{ args.service-name }}"
timeoutSeconds: 20 # defaults to 10 seconds
headers:
- key: Authorization
value: "Bearer {{ args.api-token }}"
- key: Content-Type # if body is a json, it is recommended to set the Content-Type
value: "application/json"
jsonBody: # If using jsonBody Content-Type header will be automatically set to json
key1: value_1
key2:
nestedObj: nested value
key3: "{{ args.service-name }}"
jsonPath: "{$.data.ok}"
TLS 검증 건너뛰기 (Skip TLS verification)
insecure: true 옵션을 설정하면 web 호스트의 TLS 검증을 건너뛸 수 있습니다.
metrics:
- name: webmetric
successCondition: "result.ok && result.successPercent >= 0.90"
provider:
web:
url: "https://my-server.com/api/v1/measurement?service={{ args.service-name }}"
insecure: true
headers:
- key: Authorization
value: "Bearer {{ args.api-token }}"
jsonPath: "{$.data}"
인증 (Authorization)
OAuth2 사용 시
다음 값들을 사용하여 OAuth2 클라이언트 자격 증명(client credential) 플로우를 구성할 수 있습니다.
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
name: success-rate
spec:
args:
- name: service-name
# from secret
- name: oauthSecret # This is the OAuth2 shared secret
valueFrom:
secretKeyRef:
name: oauth-secret
key: secret
metrics:
- name: webmetric
successCondition: result == true
provider:
web:
url: "http://my-server.com/api/v1/measurement?service={{ args.service-name }}"
timeoutSeconds: 20 # defaults to 10 seconds
authentication:
oauth2:
tokenUrl: https://my-oauth2-provider/token
clientId: my-client-id
clientSecret: "{{ args.oauthSecret }}"
scopes: [
"my-oauth2-scope"
]
headers:
- key: Content-Type # if body is a json, it is recommended to set the Content-Type
value: "application/json"
jsonPath: "{$.data.ok}"
이 경우 Authentication 헤더를 직접 지정할 필요가 없습니다. AnalysisRun은 먼저 해당 정보를 사용해 액세스 토큰을 얻은 다음, 메트릭 프로바이더 호출을 위해 Authorization: *** 헤더로 제공합니다.
더 알아보기 (Learn more)
- AnalysisTemplate과 AnalysisRun의 기본 개념
- Graphite 메트릭 프로바이더
- 확률적 분석의
failureCondition/successCondition작성법 - Canary 배포에서의 자동 분석(Auto Analysis) 적용