Bug 2046626 - Allow setting custom metrics for Ansible-based Operators
Summary: Allow setting custom metrics for Ansible-based Operators
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: OpenShift Container Platform
Classification: Red Hat
Component: Operator SDK
Version: 4.10
Hardware: Unspecified
OS: Unspecified
urgent
urgent
Target Milestone: ---
: 4.10.0
Assignee: Fabian von Feilitzsch
QA Contact: Fan Jia
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-01-27 05:41 UTC by Jesus M. Rodriguez
Modified: 2022-03-12 04:42 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-03-12 04:41:56 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github openshift ocp-release-operator-sdk pull 204 0 None open Bug 2045878: Allow setting custom metrics for Ansible-based Operators 2022-01-27 05:42:41 UTC
Red Hat Product Errata RHSA-2022:0056 0 None None None 2022-03-12 04:42:08 UTC

Description Jesus M. Rodriguez 2022-01-27 05:41:05 UTC
Description of problem:

Allow setting custom metrics for Ansible-based Operators

Version-Release number of selected component (if applicable):


https://github.com/operator-framework/operator-sdk/pull/5438
How reproducible:


Steps to Reproduce:
1.
2.
3.

Actual results:


Expected results:


Additional info:

Comment 2 Fan Jia 2022-01-27 11:21:49 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

Comment 5 errata-xmlrpc 2022-03-12 04:41:56 UTC
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


Note You need to log in before you can comment on or make changes to this bug.