Skip to content

[plugins/prometheus] impossible to disable the metrics endpoint #4000

Open
@synectric

Description

@synectric

Describe the bug

It's currently impossible to disable the /metrics endpoint exposed by the @graphql-yoga/plugin-prometheus plugin, passing endpoint: false to the plugin's options doesn't do what one would expect it to.

I believe the issue is on this line:

const endpoint = options.endpoint || '/metrics';

Passing false causes the "or" clause to move to the second option, i.e. the default /metrics endpoint. I would expect this line to either use the nullish coalesce operator (??) or some other solution which enables disabling the endpoint.

Temporary workaround

I'm currently disabling the endpoint using a simple plugin that overrides the default behavior by returning a 403 response on the path:

{
  onRequest: ({ url, endResponse }) => {
    if (url.pathname === '/metrics') {
      return endResponse(new Response('Forbidden', { status: 403 }));
    }
  },
}

Your Example Website or App

N/A

Steps to Reproduce the Bug or Issue

  1. Use the @graphql-yoga/plugin-prometheus Yoga plugin
  2. Pass the options { endpoint: false } to it
  3. Go to the /metrics URL in browser
  4. The metrics data is still available

Expected behavior

  1. Use the @graphql-yoga/plugin-prometheus Yoga plugin
  2. Pass the options { endpoint: false } to it
  3. Go to the /metrics URL in browser
  4. The server shows the default Yoga landing page (or equivalent)

Screenshots or Videos

No response

Platform

N/A

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions