Skip to content

Add prometheus metrics #75

Merged
nss10 merged 22 commits intomasterfrom
feat/add_prometheus
May 2, 2025
Merged

Add prometheus metrics #75
nss10 merged 22 commits intomasterfrom
feat/add_prometheus

Conversation

@nss10
Copy link
Copy Markdown
Contributor

@nss10 nss10 commented Mar 21, 2025

Link to JIRA ticket if there is one: MIDRC-857

New Features

  • Add prometheus metrics

@github-actions
Copy link
Copy Markdown

The style in this PR agrees with black. ✔️

This formatting comment was generated automatically by a script in uc-cdis/wool.

@coveralls
Copy link
Copy Markdown

coveralls commented Mar 21, 2025

Pull Request Test Coverage Report for Build 14802796595

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 36 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+1.1%) to 85.114%

Files with Coverage Reduction New Missed Lines %
app.py 3 94.34%
config.py 5 72.5%
auth.py 8 89.16%
routes/ga4gh_tes.py 20 83.33%
Totals Coverage Status
Change from base Build 14092288361: 1.1%
Covered Lines: 486
Relevant Lines: 571

💛 - Coveralls

@nss10 nss10 force-pushed the feat/add_prometheus branch from 682c5f3 to 2a1d4b8 Compare April 1, 2025 18:09
@nss10
Copy link
Copy Markdown
Contributor Author

nss10 commented Apr 1, 2025

This shall be merged after this cloud automation PR -- uc-cdis/cloud-automation#2762


# Source the environment variables from the metrics setup script
# source "${CURRENT_DIR}/setup_prometheus"
source "${CURRENT_DIR}/setup_prometheus"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is nice, but bin/_common_setup.sh was never called when the service was launched. Wanted to find out if we are planning to use this script to run the service in the future. If that is the case, then I think we can remove this section in cloud-auto PR

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's try to match what's done in gen3-user-data-library if we can

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy that! gen3-user-data-library uses a script called run.sh which initates the service, I will update that and invoke the shell script in the Dockerfile (here)[https://github.com/uc-cdis/gen3-workflow/blob/b3004eb0643f00ae5902fbf909ec80374b37b2e3/Dockerfile#L39C1-L41C27]

Copy link
Copy Markdown
Contributor Author

@nss10 nss10 Apr 16, 2025

Choose a reason for hiding this comment

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

Copy that! gen3-user-data-library uses a script called run.sh which is designed to initiate the service, I have included that change and invoked the shell script in the Dockerfile here

@nss10 nss10 marked this pull request as ready for review April 1, 2025 21:58
@nss10 nss10 requested a review from paulineribeyre April 1, 2025 21:58

# Source the environment variables from the metrics setup script
# source "${CURRENT_DIR}/setup_prometheus"
source "${CURRENT_DIR}/setup_prometheus"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's try to match what's done in gen3-user-data-library if we can



class Metrics(BaseMetrics):
def __init__(self, prometheus_dir: str, enabled: bool = True) -> None:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i think prometheus_enabled instead of just enabled would be better in case we want to expand the "metrics" class later... but maybe not worth updating cdis-python-utils...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can create a PR with this change, but it might not be worth releasing a new version just for this.

Comment on lines +10 to +11
echo "Loading environment variables from ${CURRENT_DIR}/.env"
PROMETHEUS_MULTIPROC_DIR=$(grep 'PROMETHEUS_MULTIPROC_DIR:' /src/gen3-workflow-config.yaml | awk -F': ' '{print $2}' | tr -d '"')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

mm the config is only at /src/gen3-workflow-config.yaml for cloud-automation deployments. If you run the service locally for example, it's not there.

Also i don't see PROMETHEUS_MULTIPROC_DIR in the default config, should we add it there?

and i don't get the reference to .env since we don't use that here

Copy link
Copy Markdown
Contributor Author

@nss10 nss10 Apr 17, 2025

Choose a reason for hiding this comment

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

Thanks!

  1. This script is only used when launching the service in an environment with multiple workers using gunicorn. In that scenario, it’s mandatory to have PROMETHEUS_MULTIPROC_DIR set before the application starts.
    For local development, we continue using python run.py, where the Prometheus directory is set during the initialization of the metrics object.
  2. The value is already added in the config-default.yaml here and also in config.py here
  3. The .env comment was an oversight -- I'll update that!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  1. Gotcha, could you add a comment explaining that it's made to work with cloud-automation
  2. Not sure how i missed it

@nss10 nss10 requested a review from paulineribeyre April 17, 2025 16:35
Copy link
Copy Markdown
Collaborator

@paulineribeyre paulineribeyre left a comment

Choose a reason for hiding this comment

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

@nss10 Could you make sure the last bullet in the ticket description is done before we merge this

@nss10 nss10 requested a review from paulineribeyre May 2, 2025 20:15
@nss10 nss10 merged commit d2e6e28 into master May 2, 2025
8 checks passed
@paulineribeyre paulineribeyre deleted the feat/add_prometheus branch May 8, 2025 16:18
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.

4 participants