Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

back to GunicornPrometheusMetrics, CollectorRegistry, port 9200 #244

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

charlienegri
Copy link
Contributor

Summary: this again for me exposes all the metrics at port 9200 when I run the container with docker....

Related issue: #220

Suggested reviewer(s):

Reviewer checklist:

  • The headers of all files contain a reference to the repository license
  • 100% test coverage of new code - meaning:
    • The overall test coverage increased or remained the same as before
    • Every function is accompanied with a test suite
    • Tests are both positive (testing that the function work as intended with valid data) and negative (testing that the function behaves as expected with invalid data, e.g., that correct exceptions are thrown)
    • Functions with optional arguments have separate tests for all options
  • Examples are supported by doctests
  • All tests are passing
  • All names (e.g., files, classes, functions, variables) are explicit
  • Documentation (as docstrings) is complete and understandable

The checklist is based on the S-ENDA conventions and definition of done (see General Conventions). The above points are not necessarily relevant to all contributions. In that case, please add a short explanation to help the reviewer.

@charlienegri
Copy link
Contributor Author

charlienegri commented Oct 8, 2024

Screenshot from 2024-10-08 11-55-33
@magnarem if this does not work I am out of ideas, this works for me locally, again

@charlienegri charlienegri marked this pull request as ready for review October 8, 2024 10:03
@charlienegri
Copy link
Contributor Author

@charlienegri charlienegri changed the title back to GunicornPrometheusMetrics, CollectoRegistry, port 9200 back to GunicornPrometheusMetrics, CollectorRegistry, port 9200 Oct 8, 2024
Copy link
Contributor

@magnarem magnarem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. And merged. Le'ts hope this works now.

If not, I bet the issue is related to the wsgi.py file. Since the gunicorn process loads wsgi:appthen in the wsgi.py file, I am not sure if the lines after app = App() is then loaded by gunicorn.

Also in the statefulset.yml for dmci in the tjenester-repo. The gunicorn command from the Dockerfile is overrided, so you will probably need to add the -c /src/gunicorn_prometheus_config.py to the command: for the dmci container in the statefulset.yml too. And make sure the 9200 is exposded and scraped

@magnarem magnarem merged commit 0e2ec83 into main Oct 8, 2024
5 checks passed
@magnarem magnarem deleted the GunicornPrometheusMetrics_collectoregistry_port9200 branch October 8, 2024 12:11
@charlienegri
Copy link
Contributor Author

Approved. And merged. Le'ts hope this works now.

If not, I bet the issue is related to the wsgi.py file. Since the gunicorn process loads wsgi:appthen in the wsgi.py file, I am not sure if the lines after app = App() is then loaded by gunicorn.

Also in the statefulset.yml for dmci in the tjenester-repo. The gunicorn command from the Dockerfile is overrided, so you will probably need to add the -c /src/gunicorn_prometheus_config.py to the command: for the dmci container in the statefulset.yml too. And make sure the 9200 is exposded and scraped

we got the flask metrics exposed correctly at the 9200 port tho initially, before I implemente the custom ones, so I think that the GunicornPrometheusMetrics() or variants of it in wsgi.py works, but the problem is having both those default ones and the custom one exposed at the same port and by the same collector

@charlienegri
Copy link
Contributor Author

charlienegri commented Oct 8, 2024

mmh /src/gunicorn_prometheus_config.py' doesn't exist
I must have merged too fast on the other side, restarted the pod now

@magnarem
Copy link
Contributor

magnarem commented Oct 8, 2024

yeah. you probably not need this copy statement.
Since the gunicorn_prometheus_config.py resides in container/ folder together with the wsgi.py both files are copied to root, so you will not need this line COPY container/gunicorn_prometheus_config.py /src

and then the gunicorn command should work with:

CMD gunicorn -c gunicorn_prometheus_config.py --worker-class sync --workers 5 --bind 0.0.0.0:8000 wsgi:app --keep-alive 5 --log-level info

Also I see no problem with our custom metrics (the failed dist) you implemented is exposed on different port than the other prometheus flask metrics. You can have multiple annotations for scraping in kubernetes I imagine.

@magnarem
Copy link
Contributor

magnarem commented Oct 8, 2024

Also for the 9200 Port, you will probably have to add a special ingress in the ingress.yml in the dmci base folder.

 rules:
    - host: "dmci.s-enda.k8s.met.no"
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: dmci
                port:
                  name: http
        - path:/flask-metrics
         pathType: Prefix?
         backend:
         service:
           name: dmci
           port:
             name: http-flask-metrics
             ```
             
             and then in statefulset
             
             ```
               ports:
            - name: http
              containerPort: 8000
              protocol: TCP
         - name: http-flask-metrics
           port: 9200
           protocol: TCP
           ``

@charlienegri
Copy link
Contributor Author

charlienegri commented Oct 8, 2024

the exposure of 9200 in the statefulset is already there, I had added it, removed it and added it back after last update
the endpoint seems also to have everything now, I am happy with this finally --> https://dmci.s-enda-dev.k8s.met.no/metrics

@charlienegri
Copy link
Contributor Author

yeah. you probably not need this copy statement. Since the gunicorn_prometheus_config.py resides in container/ folder together with the wsgi.py both files are copied to root, so you will not need this line COPY container/gunicorn_prometheus_config.py /src

and then the gunicorn command should work with:

CMD gunicorn -c gunicorn_prometheus_config.py --worker-class sync --workers 5 --bind 0.0.0.0:8000 wsgi:app --keep-alive 5 --log-level info

Also I see no problem with our custom metrics (the failed dist) you implemented is exposed on different port than the other prometheus flask metrics. You can have multiple annotations for scraping in kubernetes I imagine.

gunicorn_prometheus_config.py is indeed in the root folder of the container so as you say we can skip the copy to src step

@charlienegri
Copy link
Contributor Author

charlienegri commented Oct 8, 2024

w̶h̶i̶l̶e̶ ̶l̶o̶o̶k̶i̶n̶g̶ ̶a̶t̶ ̶t̶h̶e̶ ̶f̶e̶d̶e̶r̶a̶t̶e̶d̶ ̶m̶e̶t̶r̶i̶c̶s̶ ̶I̶ ̶s̶e̶e̶ ̶s̶o̶m̶e̶ ̶i̶n̶c̶o̶n̶s̶i̶s̶t̶e̶n̶c̶i̶e̶s̶.̶.̶ ̶I̶ ̶f̶e̶a̶r̶ ̶t̶h̶e̶ ̶e̶x̶p̶o̶s̶u̶r̶e̶ ̶m̶i̶g̶h̶t̶ ̶h̶a̶p̶p̶e̶n̶ ̶o̶n̶ ̶o̶n̶e̶ ̶i̶n̶s̶t̶a̶n̶c̶e̶ ̶o̶n̶l̶y̶ ̶:̶/̶
̶.̶.̶ ̶t̶h̶i̶s̶ ̶m̶i̶g̶h̶t̶ ̶b̶e̶ ̶d̶u̶e̶ ̶t̶o̶ ̶t̶h̶e̶ ̶u̶s̶e̶ ̶o̶f̶ ̶G̶u̶n̶i̶c̶o̶r̶n̶P̶r̶o̶m̶e̶t̶h̶e̶u̶s̶M̶e̶t̶r̶i̶c̶s̶ ̶i̶n̶s̶t̶e̶a̶d̶ ̶o̶f̶ ̶G̶u̶n̶i̶c̶o̶r̶n̶I̶n̶t̶e̶r̶n̶a̶l̶P̶r̶o̶m̶e̶t̶h̶e̶u̶s̶M̶e̶t̶r̶i̶c̶s̶?̶ ̶s̶e̶e̶ ̶h̶t̶t̶p̶s̶:̶/̶/̶g̶i̶t̶h̶u̶b̶.̶c̶o̶m̶/̶r̶y̶c̶u̶s̶8̶6̶/̶p̶r̶o̶m̶e̶t̶h̶e̶u̶s̶_̶f̶l̶a̶s̶k̶_̶e̶x̶p̶o̶r̶t̶e̶r̶/̶b̶l̶o̶b̶/̶m̶a̶s̶t̶e̶r̶/̶e̶x̶a̶m̶p̶l̶e̶s̶/̶g̶u̶n̶i̶c̶o̶r̶n̶-̶m̶u̶l̶t̶i̶p̶r̶o̶c̶e̶s̶s̶-̶1̶0̶9̶/̶s̶e̶r̶v̶e̶r̶.̶p̶y̶
̶b̶u̶t̶ ̶i̶n̶ ̶m̶y̶ ̶p̶r̶e̶v̶i̶o̶u̶s̶ ̶a̶t̶t̶e̶m̶p̶t̶ ̶t̶o̶ ̶u̶s̶e̶ ̶t̶h̶a̶t̶ ̶t̶h̶a̶n̶ ̶w̶e̶ ̶w̶e̶r̶e̶ ̶m̶i̶s̶s̶i̶n̶g̶ ̶t̶h̶e̶ ̶f̶l̶a̶s̶k̶ ̶s̶t̶a̶n̶d̶a̶r̶d̶ ̶m̶e̶t̶r̶i̶c̶s̶ this might be correct after all, one instance only is consistent with the catalog-rebuilder-flask

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants