Bug 2046626
| Summary: | Allow setting custom metrics for Ansible-based Operators | ||
|---|---|---|---|
| Product: | OpenShift Container Platform | Reporter: | Jesus M. Rodriguez <jesusr> |
| Component: | Operator SDK | Assignee: | Fabian von Feilitzsch <fabian> |
| Status: | CLOSED ERRATA | QA Contact: | Fan Jia <jfan> |
| Severity: | urgent | Docs Contact: | |
| Priority: | urgent | ||
| Version: | 4.10 | CC: | aos-bugs |
| Target Milestone: | --- | ||
| Target Release: | 4.10.0 | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| Whiteboard: | |||
| Fixed In Version: | Doc Type: | If docs needed, set a value | |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2022-03-12 04:41:56 UTC | Type: | Bug |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
| Embargoed: | |||
|
Description
Jesus M. Rodriguez
2022-01-27 05:41:05 UTC
test env:
1)operator-sdk version: "v1.16.0-ocp", commit: "fedd2e9222038fa5e8221e513da1c62f0767d94a", kubernetes version: "v1.22", go version: "go1.17.4", GOOS: "linux", GOARCH: "amd64"
2) - name: operator_sdk.util
version: "0.4.0"
test result:
I test this by build one ansible operator with the latest operator-sdk and file the tasks/main.yml like this:
—
tasks file for Memcached
name: start k8sstatus
k8s:
definition:
kind: Deployment
apiVersion: apps/v1
metadata:
name: '{{ ansible_operator_meta.name }}-memcached'
namespace: '{{ ansible_operator_meta.namespace }}'
spec:
replicas: "size"
selector:
matchLabels:
app: memcached
template:
metadata:
labels:
app: memcached
spec:
containers:
- name: memcached
command:
- memcached
- -m=64
- -o
- modern
- -v
image: "docker.io/memcached:1.4.36-alpine"
ports:
- containerPort: 11211
osdk_metric:
name: my_thing_counter
description: This metric counts things
counter: {}
osdk_metric:
name: my_counter_metric
description: Add 3.14 to the counter
counter:
increment: yes
osdk_metric:
name: my_gauge_metric
description: Create my gague and set it to 2.
gauge:
set: 2
osdk_metric:
name: my_histogram_metric
description: Observe my histogram
histogram:
observe: 2
osdk_metric:
name: my_summary_metric
description: Observe my summary
summary:
observe: 2
The logs of ansible operator run:
`
{"level":"info","ts":1643272801.0894716,"logger":"apiserver","msg":"Starting to serve metrics listener","Address":"localhost:5050"}
I0127 08:40:01.102772 7 leaderelection.go:258] successfully acquired lease ansiblemetrics-system/ansiblemetrics
{"level":"info","ts":1643272801.1029117,"logger":"controller.testmetrics-controller","msg":"Starting EventSource","source":"kind source: metrics.testmetrics.com/v1, Kind=Testmetrics"}
`
The metrics:
1)#oc exec ansiblemetrics-controller-manager-58dd4f465-ws8j8 – curl -k -H "Authorization: Bearer $token" 'https://10.129.2.70:8443/metrics' | grep my_counter
HELP my_counter_metric Add 3.14 to the counter
TYPE my_counter_metric counter
my_counter_metric 2
2)#oc exec ansiblemetrics-controller-manager-58dd4f465-ws8j8 – curl -k -H "Authorization: Bearer $token" 'https://10.129.2.70:8443/metrics' | grep gague
HELP my_gauge_metric Create my gague and set it to 2.
HELP my_gauge_metric Create my gague and set it to 2.
3)#oc exec ansiblemetrics-controller-manager-58dd4f465-ws8j8 – curl -k -H "Authorization: Bearer $token" 'https://10.129.2.70:8443/metrics' | grep Observe
HELP my_histogram_metric Observe my histogram
HELP my_summary_metric Observe my summary
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory (Moderate: OpenShift Container Platform 4.10.3 security update), and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHSA-2022:0056 |