XanderD99 / strapi-prometheus

Strapi prometheus plugin
MIT License
18 stars 4 forks source link

Issue with Graphql configuration #24

Closed DevOps-Hestabit-1 closed 1 month ago

DevOps-Hestabit-1 commented 1 month ago

When I add Graphql configuration in the plugin.js file.Graphql requests crash and face this issues

/app/CMS/node_modules/strapi-prometheus/apollo/index.js:82
              resolveEnd({ ...fieldLabels, status });
              ^
TypeError: resolveEnd is not a function
    at /app/CMS/node_modules/strapi-prometheus/apollo/index.js:82:15
    at /app/CMS/node_modules/apollo-server-core/dist/utils/dispatcher.js:57:17
    at /app/CMS/node_modules/apollo-server-core/dist/utils/schemaInstrumentation.js:76:28
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Strapi version : v4.25.7 Node version : v20.15.1 Ubuntu version : 22.04

XanderD99 commented 1 month ago

Just to make sure, have you enabled the apollo metrics in you plugin config? This is by default disabled, as I just doublechecked this isn't documented correctly in the readme.

So update your plugin config to look like this:

// enable plugin with default configuration.
module.exports = [
  'strapi-prometheus': {
    enabled: true,
    config: {
      enabledMetrics: {
        apollo: true, // metrics regarding graphql
      },
  }
];

Also already an FYI I am rewriting the plugin for the v5 release. This part will be removed from this plugin as it is not a strapi plugin but a apollo server plugin.

DevOps-Hestabit-1 commented 1 month ago

Thank You for your response. It is included in this

// config/plugins.js

// enable plugin with default configuration.
module.exports = [
  'strapi-prometheus': {
    enabled: true,
    config: {
      // add prefix to all the prometheus metrics names.
      prefix: '',

      // use full url instead of matched url
      // true  => path label: `/api/models/1`
      // false => path label: `/api/models/:id`
      fullURL: false,

      // include url query in the url label
      // true  => path label: `/api/models?limit=1`
      // false => path label: `/api/models`
      includeQuery: false,

      // metrics that will be enabled, by default they are all enabled.
      enabledMetrics: {
        koa: true, // koa metrics
        process: true, // metrics regarding the running process
        http: true, // http metrics like response time and size
        apollo: true, // metrics regarding graphql
      },

      // interval at which rate metrics are collected in ms
      interval: 10_000,

      // set custom/default labels to all the prometheus metrics
      customLabels: {
        name: "strapi-prometheus",
      },

      // run metrics on seperate server / port
      server: {
        // when enabled metrics will run seperatly from the strapi instance. It will still go up / down with strapi
        // if disabled it will create /api/metrics endpoint on main strapi instance
        // when enabled install run `npm i express`
        enabled: false
        port: 9000,
        host: 'localhost',
        path: '/metrics',
      }
    }
  }
];

I faced the problem when I added this

// config/plugins.js
const { apolloPrometheusPlugin } = require('strapi-prometheus')

module.exports = [
  'strapi-prometheus': {
    enabled: true,
  },
  graphql: {
    enabled: true,
    config: {
      apolloServer: {
        plugins: [apolloPrometheusPlugin], // add the plugin to get apollo metrics
        tracing: true, // this must be true to get some of the data needed to create the metrics
      }
    }
  }
}

Please let me know If I am missing something.

XanderD99 commented 1 month ago

Yes there is a mistake in the example configuration. It says that it enables all metrics by default but that is not true.

So you need to update the plugin config to look something like this:

  'strapi-prometheus': {
    enabled: true,
    config: {
      enabledMetrics: {
        apollo: true, // metrics regarding graphql
      },
  }

So that the apollo metrics get loaded. By deault this is false, so if you copy the graphql example those metrics won't load and therefor errors will be thrown when trying to use them.

XanderD99 commented 1 month ago

I updated the readme and example to correctly indicate that it is not enabled

DevOps-Hestabit-1 commented 1 month ago

Its fixed thank you.