Skip to content

Refactor Postgres exporter to make it re-usable as a Go library#1330

Open
ArthurSens wants to merge 2 commits into
masterfrom
refactor-postgres-exporter
Open

Refactor Postgres exporter to make it re-usable as a Go library#1330
ArthurSens wants to merge 2 commits into
masterfrom
refactor-postgres-exporter

Conversation

@ArthurSens

Copy link
Copy Markdown
Contributor

Superseeds #1297 and #1299


This PR refactors the Postgres exporter codebase so it can be easily embedded as a Go library in downstream projects. The architecture I'm aiming for in this PR is documented here.

To summarize:

  • We're abstracting the concept of "One Postgres exporter" into an object called Runtime. This Runtime contains all Prometheus collectors in isolation.
  • We have a Config package that holds all possible user-facing configuration, with the exception of AuthModules. That includes all CLI flags, including the enabled collectors.
  • cmd/postgres/main.go stitches CLI flags, config, Runtime, and http handler together
  • cmd/postgres/probes.go uses the Runtime abstraction to handle multiple postgres targets.

For more details on the architecture, I recommend reading the docs we wrote or the Stackdriver exporter codebase, which already follows this architecture!

Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Comment thread collectors/runtime.go
Comment on lines +37 to +39
if !cfg.Validated() {
return nil, errors.New("config has not been validated; call cfg.Validate before NewRuntime")
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I kinda like what you did here, https://github.com/prometheus/prometheus-opentelemetry-collector/pull/11/changes#diff-e855075d0398417658889b1c58d1abee6934a122028a324919d2549250e16e72R60-R64, to have it call validate. We might want to log a warning since we would hope it would be done ahead of time but avoiding the error seems nice.

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