diff --git a/charts/vela-core/templates/defwithtemplate/check-metrics.yaml b/charts/vela-core/templates/defwithtemplate/check-metrics.yaml new file mode 100644 index 000000000..8ab5e1186 --- /dev/null +++ b/charts/vela-core/templates/defwithtemplate/check-metrics.yaml @@ -0,0 +1,59 @@ +# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file. +# Definition source cue file: vela-templates/definitions/internal/check-metrics.cue +apiVersion: core.oam.dev/v1beta1 +kind: WorkflowStepDefinition +metadata: + annotations: + custom.definition.oam.dev/category: Application Delivery + definition.oam.dev/description: Verify application's metrics + labels: + custom.definition.oam.dev/catalog: Delivery + name: check-metrics + namespace: {{ include "systemDefinitionNamespace" . }} +spec: + schematic: + cue: + template: | + import ( + "vela/op" + ) + + check: op.#PromCheck & { + query: parameter.query + metricEndpoint: parameter.metricEndpoint + condition: parameter.condition + stepID: context.stepSessionID + duration: parameter.duration + failDuration: parameter.failDuration + } + + fail: op.#Steps & { + if check.failed != _|_ { + if check.failed == true { + breakWorkflow: op.#Fail & { + message: check.message + } + } + } + } + + wait: op.#ConditionalWait & { + continue: check.result + if check.message != _|_ { + message: check.message + } + } + + parameter: { + // +usage=Query is a raw prometheus query to perform + query: string + // +usage=The HTTP address and port of the prometheus server + metricEndpoint?: "http://prometheus-server.o11y-system.svc:9090" | string + // +usage=Condition is an expression which determines if a measurement is considered successful. eg: >=0.95 + condition: string + // +usage=Duration defines the duration of time required for this step to be considered successful. + duration?: *"5m" | string + // +usage=FailDuration is the duration of time that, if the check fails, will result in the step being marked as failed. + failDuration?: *"2m" | string + } + diff --git a/charts/vela-minimal/templates/defwithtemplate/check-metrics.yaml b/charts/vela-minimal/templates/defwithtemplate/check-metrics.yaml new file mode 100644 index 000000000..8ab5e1186 --- /dev/null +++ b/charts/vela-minimal/templates/defwithtemplate/check-metrics.yaml @@ -0,0 +1,59 @@ +# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file. +# Definition source cue file: vela-templates/definitions/internal/check-metrics.cue +apiVersion: core.oam.dev/v1beta1 +kind: WorkflowStepDefinition +metadata: + annotations: + custom.definition.oam.dev/category: Application Delivery + definition.oam.dev/description: Verify application's metrics + labels: + custom.definition.oam.dev/catalog: Delivery + name: check-metrics + namespace: {{ include "systemDefinitionNamespace" . }} +spec: + schematic: + cue: + template: | + import ( + "vela/op" + ) + + check: op.#PromCheck & { + query: parameter.query + metricEndpoint: parameter.metricEndpoint + condition: parameter.condition + stepID: context.stepSessionID + duration: parameter.duration + failDuration: parameter.failDuration + } + + fail: op.#Steps & { + if check.failed != _|_ { + if check.failed == true { + breakWorkflow: op.#Fail & { + message: check.message + } + } + } + } + + wait: op.#ConditionalWait & { + continue: check.result + if check.message != _|_ { + message: check.message + } + } + + parameter: { + // +usage=Query is a raw prometheus query to perform + query: string + // +usage=The HTTP address and port of the prometheus server + metricEndpoint?: "http://prometheus-server.o11y-system.svc:9090" | string + // +usage=Condition is an expression which determines if a measurement is considered successful. eg: >=0.95 + condition: string + // +usage=Duration defines the duration of time required for this step to be considered successful. + duration?: *"5m" | string + // +usage=FailDuration is the duration of time that, if the check fails, will result in the step being marked as failed. + failDuration?: *"2m" | string + } + diff --git a/references/docgen/def-doc/workflowstep/check-metrics.eg.md b/references/docgen/def-doc/workflowstep/check-metrics.eg.md new file mode 100644 index 000000000..046ca56fb --- /dev/null +++ b/references/docgen/def-doc/workflowstep/check-metrics.eg.md @@ -0,0 +1,35 @@ +```yaml +apiVersion: core.oam.dev/v1beta1 +kind: Application +metadata: + name: canary-demo + annotations: + app.oam.dev/publishVersion: v2 +spec: + components: + - name: canary-demo + type: webservice + properties: + image: wangyikewyk/canarydemo:v2 + ports: + - port: 8090 + traits: + - type: scaler + properties: + replicas: 5 + - type: gateway + properties: + domain: canary-demo.com + http: + "/version": 8090 + workflow: + steps: + - name: 200-status-percent-2-phase + type: check-metrics + timeout: 3m + properties: + query: sum(irate(nginx_ingress_controller_requests{host="canary-demo.com",status="200"}[5m]))/sum(irate(nginx_ingress_controller_requests{host="canary-demo.com"}[2m])) + promAddress: "http://prometheus-server.o11y-system.svc:9090" + condition: ">=0.95" + duration: 2m +``` diff --git a/vela-templates/definitions/internal/workflowstep/check-metrics.cue b/vela-templates/definitions/internal/workflowstep/check-metrics.cue new file mode 100644 index 000000000..7588f629d --- /dev/null +++ b/vela-templates/definitions/internal/workflowstep/check-metrics.cue @@ -0,0 +1,54 @@ +import ( + "vela/op" +) + +"check-metrics": { + type: "workflow-step" + labels: { + "catalog": "Delivery" + } + annotations: { + "category": "Application Delivery" + } + description: "Verify application's metrics" +} +template: { + check: op.#PromCheck & { + query: parameter.query + metricEndpoint: parameter.metricEndpoint + condition: parameter.condition + stepID: context.stepSessionID + duration: parameter.duration + failDuration: parameter.failDuration + } + + fail: op.#Steps & { + if check.failed != _|_ { + if check.failed == true { + breakWorkflow: op.#Fail & { + message: check.message + } + } + } + } + + wait: op.#ConditionalWait & { + continue: check.result + if check.message != _|_ { + message: check.message + } + } + + parameter: { + // +usage=Query is a raw prometheus query to perform + query: string + // +usage=The HTTP address and port of the prometheus server + metricEndpoint?: "http://prometheus-server.o11y-system.svc:9090" | string + // +usage=Condition is an expression which determines if a measurement is considered successful. eg: >=0.95 + condition: string + // +usage=Duration defines the duration of time required for this step to be considered successful. + duration?: *"5m" | string + // +usage=FailDuration is the duration of time that, if the check fails, will result in the step being marked as failed. + failDuration?: *"2m" | string + } +}