8000 feat(stackit): postgres flex service discovery by h3adex · Pull Request #16771 · prometheus/prometheus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(stackit): postgres flex service discovery #16771

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

h3adex
Copy link
@h3adex h3adex commented Jun 24, 2025

This PR adds support for monitoring managed Postgres databases by leveraging our Postgres API for automatic service discovery. It introduces a role-based configuration, allowing Prometheus to distinguish between server and postgres_flex instances. This is a foundational change for future support of additional managed services, such as mongodb_flex, which I plan to add in a follow-up PR. The change introduces a breaking update: specifying a role is now required. Previously, only IaaS resources were supported and no explicit role was needed. Since this feature has not yet been released, I believe it’s acceptable to introduce this change now. Alternatively, we could set server as the default role to preserve compatibility—happy to adjust based on feedback.

Screenshots from my local E2E Tests
postgres-flex-metrics
postgres-flex-metrics-2

My Test setup:

scrape_configs:
  # Make Prometheus scrape itself for metrics.
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]

  # Discover postgres flex database
  - job_name: "postgres_flex_discovery"
    stackit_sd_configs:
      - project: 673704cf-5af4-4e7a-a961-5eb6d6384c2e
        role: "postgres_flex"
        authorization:
          credentials: "ey..."

    authorization:
      type: Bearer
      credentials: "ey..."

  # Discover IaaS Instance
  - job_name: "iaas_discovery"
    stackit_sd_configs:
      - project: 673704cf-5af4-4e7a-a961-5eb6d6384c2e
        role: "server"
        authorization:
          credentials: "ey..."

@h3adex h3adex force-pushed the feat/stackit-postgres-flex-integration branch 8 times, most recently from 3eb548d to 021ec78 Compare June 24, 2025 09:59
Signed-off-by: Mauritz Uphoff <mauritz.uphoff@stackit.cloud>
@h3adex h3adex force-pushed the feat/stackit-postgres-flex-integration branch from 021ec78 to 9f18427 Compare June 24, 2025 10:07
MAINTAINERS.md Outdated
@@ -11,7 +11,7 @@ Maintainers for specific parts of the codebase:
* `discovery`
* `azure`: Jan-Otto Kröpke (<mail@jkroepke.de> / @jkroepke)
* `k8s`: Frederic Branczyk (<fbranczyk@gmail.com> / @brancz)
* `stackit`: Jan-Otto Kröpke (<mail@jkroepke.de> / @jkroepke)
* `stackit`: Jan-Otto Kröpke (<mail@jkroepke.de> / @jkroepke), Mauritz Uphoff (<mauritz.uphoff@stackit.cloud> / @h3adex)
Copy link
Member

Choose a reason for hiding this comment

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

not sure, if external maintaners are fine?

Copy link
Author

Choose a reason for hiding this comment

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

Removed my mail

reqBody, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = fmt.Fprint(w, err)
return
}

// Expecting HTTP form encoded body with the field assertion.
// JWT always start with "ey" (base64url encoded).
if !bytes.HasPrefix(reqBody, []byte("assertion=ey")) {
Copy link
Member

Choose a reason for hiding this comment

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

Some comments are requested in an earlier PR, they should not be removed.

Comment on lines +36 to +39
stackitLabelPostgresFlexID = stackitLabelPrefix + "postgres_flex_id"
stackitLabelPostgresFlexName = stackitLabelPrefix + "postgres_flex_name"
stackitLabelPostgresFlexStatus = stackitLabelPrefix + "postgres_flex_status"
stackitLabelPostgresFlexRegion = stackitLabelPrefix + "postgres_flex_region"
Copy link
Member

Choose a reason for hiding this comment

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

Please check, if the exists labels can be re-used. (I guess yes)

Copy link
Author

Choose a reason for hiding this comment

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

I'm not entirely sure I understand your point. Could you please elaborate a bit more?

Copy link
Member
@jkroepke jkroepke Jun 30, 2025

Choose a reason for hiding this comment

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

const (
stackitLabelPrefix = model.MetaLabelPrefix + "stackit_"
stackitLabelProject = stackitLabelPrefix + "project"
stackitLabelID = stackitLabelPrefix + "id"
stackitLabelName = stackitLabelPrefix + "name"
stackitLabelStatus = stackitLabelPrefix + "status"
stackitLabelPowerStatus = stackitLabelPrefix + "power_status"
stackitLabelAvailabilityZone = stackitLabelPrefix + "availability_zone"
stackitLabelPublicIPv4 = stackitLabelPrefix + "public_ipv4"
)

I tried to ask, if the existing labels can be used (without role prefix) instead define new labels for each role.

ref: #16401 (comment)


The postgres_flex role dynamically discovers scrape targets using the [PostgresFlex API](https://docs.api.eu01.stackit.cloud/documentation/postgres-flex-service/version/v2#tag/instance).

To enable this scrape configuration, a valid Authorization Bearer Token must be provided. Refer to [this example configuration](../../documentation/examples/prometheus-stackit.yml) for guidance.
Copy link
Member

Choose a reason for hiding this comment

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

A good hint would be useful here that the recommended STACKIT Service Account Key is not supported here.

See below for the configuration options for STACKIT discovery:

```yaml
# The STACKIT project
project: <string>

# STACKIT role of entities that should be discovered.
# postgres_flex and server are supported.
[ role : <string> ]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
[ role : <string> ]
role : <string>

If role is required, the brackets should be omit.

Signed-off-by: Mauritz Uphoff <mauritz.uphoff@stackit.cloud>
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
0