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

feat: make prometheus config preventServerStart optional #1375

Merged
merged 9 commits into from
Sep 29, 2020

Conversation

legendecas
Copy link
Member

@legendecas legendecas commented Aug 3, 2020

Which problem is this PR solving?

There are a couple of reasons to leave the PrometheusExporterConfig.startServer false by default. First, it is async so we have another call that a user can do asynchronously so they can ensure it actually started. Second, it grabs a port on the host computer. This type of thing is best left explicit so the user is not surprised.

However, by most situations (and in examples), the startServer config was mostly set to true. And it is quite easy to forget to set the config and failed to find the Prometheus working as expected. In this situation, it can be very helpful to start the server by default and provide an option to prevent the server from starting (grabbing a port from the host).

Short description of the changes

  • the config startServer is replaced by preventServerStart.

@codecov
Copy link

codecov bot commented Aug 3, 2020

Codecov Report

Merging #1375 into master will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #1375   +/-   ##
=======================================
  Coverage   93.18%   93.18%           
=======================================
  Files         156      156           
  Lines        4854     4854           
  Branches      986      986           
=======================================
  Hits         4523     4523           
  Misses        331      331           
Impacted Files Coverage Δ
...etry-exporter-prometheus/src/PrometheusExporter.ts 90.16% <100.00%> (ø)

*/
startServer?: boolean;
startServer: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Why did you make this configuration option required? Should it not just default to true?

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason startServer defaults to false have been stated at the description of the PR "it grabs a port on the host computer. This type of thing is best left explicit so the user is not surprised" -- which is copy-pasted from previous Gitter chat history I considered as a fair reason (unfortunately Gitter doesn't provide chat history links).

Copy link
Member

Choose a reason for hiding this comment

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

I am leaning towards default to true, prometheus is meant to be scraped in most cases. The default port of 9464 is meant for this as per https://github.com/prometheus/prometheus/wiki/Default-port-allocations

Copy link
Member

Choose a reason for hiding this comment

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

I believe the gitter chat @legendecas referenced was actually me :)

Think I see this one both ways. It is unfortunate that we have to grab a port, but the exporter really is useless without it so I would say it's probably ok to just do it.

Copy link
Member

@obecny obecny left a comment

Choose a reason for hiding this comment

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

I would argue that boolean parameter should be ever required. By default anything what is boolean and is not defined is simply false, we should not change it, In js if user doesn't define config we will have "an object undefined exception", I don't see any reason why we should have it. And just writing everywhere

startServer: false

doesn't look very intuitive why would you even want that

@@ -68,17 +68,13 @@ describe('PrometheusExporter', () => {
}
);
});

it('should not start the server by default', () => {
Copy link
Member

Choose a reason for hiding this comment

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

I think this test is still relevant , if user doesn't provide anything (when using in pure js for example) the server should not start right ?

@@ -59,7 +58,7 @@ export class PrometheusExporter implements MetricExporter {
* @param config Exporter configuration
* @param callback Callback to be called after a server was started
*/
constructor(config: ExporterConfig = {}, callback?: () => void) {
constructor(config: ExporterConfig, callback?: () => void) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this should not be changed, if in js user will not define any config we don't want the error "object is undefined" to be thrown.

Copy link
Member

Choose a reason for hiding this comment

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

@legendecas any update here?

@dyladan
Copy link
Member

dyladan commented Aug 7, 2020

By default anything what is boolean and is not defined is simply false

Maybe a better option is to rename startServer to preventServerStart or something?

@dyladan
Copy link
Member

dyladan commented Sep 23, 2020

I would argue that boolean parameter should be ever required. By default anything what is boolean and is not defined is simply false, we should not change it, In js if user doesn't define config we will have "an object undefined exception", I don't see any reason why we should have it. And just writing everywhere

startServer: false

doesn't look very intuitive why would you even want that

@legendecas what do you think about inverting the name to preventStartServer or similar?

@naseemkullah
Copy link
Member

By default anything what is boolean and is not defined is simply false

Maybe a better option is to rename startServer to preventServerStart or something?

serverless? 😄

@legendecas
Copy link
Member Author

@dyladan what do you think about inverting the name to preventStartServer or similar?

I'm good with that, will do a quick update late today. But I'm wondering what the use case will be if we set preventStartServer: true?

@dyladan
Copy link
Member

dyladan commented Sep 24, 2020

@legendecas we could just remove the option entirely, but then there is no way for the user to stop the exporter from grabbing a port. The usecase is admittedly entirely theoretical, but one could imagine a user that wants to defer server start until some precondition is met like waiting for a port to become available.

# Conflicts:
#	packages/opentelemetry-exporter-prometheus/src/prometheus.ts
#	packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts
@legendecas
Copy link
Member Author

legendecas commented Sep 24, 2020

@dyladan @obecny @naseemkullah @mayurkale22 the startServer option has been replaced by preventServerStart, which is false by default -- i.e. starting server by default. PTAL :)

Copy link
Member

@obecny obecny left a comment

Choose a reason for hiding this comment

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

lgtm

@obecny obecny changed the title feat: make prometheus config startServer mandatory feat: make prometheus config preventServerStart optional Sep 24, 2020
@obecny
Copy link
Member

obecny commented Sep 24, 2020

is this still a breaking change now @dyladan ?

@obecny obecny merged commit 24ffd16 into open-telemetry:master Sep 29, 2020
@legendecas legendecas deleted the prom-start-server-option branch October 1, 2020 17:54
pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Dec 15, 2023
…elemetry#1375)

* fix(instrumentation-fs): fix instrumentation of `fs/promises`

* Revert "fix(instrumentation-fs): fix instrumentation of `fs/promises`"

This reverts commit 90d9f0d68960ef647bbe5b7347ad6c97f936651e.

* fix(instrumentation-fs): fix instrumentation of `fs/promises`

* chore(instrumentation-fs): fix lint error

* chore(instrumentation-fs): hard-code `R_OK` value for node 14

* chore(instrumentation-fs): fix supported version for `fs/promises`

* chore(instrumentation-fs): incorporate changes from open-telemetry#1332

* chore(instrumentation-fs): consolidate common test utilities

---------

Co-authored-by: Haddas Bronfman <[email protected]>
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.

5 participants