Make service discoveries removable through build tags#17736
Conversation
|
I fail to understand the logic behind this. Why do you import service discoveries you do not need? |
krajorama
left a comment
There was a problem hiding this comment.
approved but see @roidelapluie question
Could you elaborate? I'm struggling to understand the question... The change I'm doing is to enable not importing SDs you don't need 🤔 Before this change, all SD's imports are in the same file and they are all registered together by their init() function, like here for example. With the change in this PR I'm splitting the imports into separate files and each file have their respective tags for exclusion |
|
One thing that I think might be missing here is documentation, I'm not sure where's the right place for that though |
|
I think @roidelapluie is asking about why the existing plugins.yml / generator is not sufficient to configure the discovery inclusion. This is what we've used so far to build customized binaries. |
Oh gotcha! To be honest, I didn't notice that |
|
I think build tags are probably a better Go-native way to do the configuration. If we do this, we should remove the |
Yes, I think keeping both would be a distraction.
In the initial design, those projects should simply not import the libraries then and have their own "plugins" package which imports the SD they want. |
Got it, I guess that works for most use cases with exception for the OTel Collector 🙈. The collector was designed to be as customizable as possible during build time, our goal there is to let users build their own collectors and not decide things for them |
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
bec9083 to
f198b86
Compare
Co-authored-by: Julien <291750+roidelapluie@users.noreply.github.com> Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This PR is built on top of prometheus/prometheus#17736. There are a lot of go mod changes, and that also inherits fixes to interface changes that were made since Prometheus 3.8 The only change that is really about making SDs removable is this change in imports in `factory.go`: ```diff - _ "github.com/prometheus/prometheus/discovery/install" // init() of this package registers service discovery impl. + _ "github.com/prometheus/prometheus/plugins" // init() of this package registers service discovery impl. ``` <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes #44406 <!--Describe what testing was performed and which tests were added.--> #### Testing Used two builder configs and measured the binary size difference: Without build tags(120MB): ```yaml dist: module: github.com/open-telemetry/otelcontribcol name: otelcontribcol version: 0.143.0 output_path: ./cmd/otelcontribcol/sd-test/full receivers: - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.143.0 path: ./receiver/prometheusreceiver exporters: - gomod: go.opentelemetry.io/collector/exporter/debugexporter v0.143.0 ``` With build tags(63MG): ```yaml dist: module: github.com/open-telemetry/otelcontribcol name: otelcontribcol version: 0.143.0 output_path: ./cmd/otelcontribcol/sd-test/no-sd build_tags: "remove_all_sd" receivers: - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.143.0 path: ./receiver/prometheusreceiver exporters: - gomod: go.opentelemetry.io/collector/exporter/debugexporter v0.143.0 ``` --------- Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Prometheus ships with quite a few service discovery mechanisms, each bringing its own dependencies (AWS SDK, Azure SDK, Kubernetes client-go, etc.). This results in a ~170MB binary even for users who only need a subset of these SDs.
This PR introduces build tags that allow users to exclude specific service discoveries at compile time, reducing binary size for deployments that don't require all SD mechanisms.
This is useful for:
What I'm doing here is splitting the codebase that imports service discoveries into several files, each with its own build tag for exclusion, so that all service discoveries continue to be enabled by default.
Results
Does this PR introduce a user-facing change?