slanatech / swagger-stats

API Observability. Trace API calls and Monitor API performance, health and usage statistics in Node.js Microservices.
https://swaggerstats.io/
MIT License
891 stars 136 forks source link

Endpoint not found #177

Closed ghost closed 2 years ago

ghost commented 2 years ago

I'm adding swagger-stats as a middleware in Fastify. So I guess this whole thing is tricky.

Reproducing the Fastify example in docs didn't work at all as it messed with other Fastify plugins (mongo and others).

But anyway, I tried the encapsulation and it didn't show any errors, so I think the Fastify part of this is fine,

const swagger = require('./config/options/swagger')
fastify.register(require('fastify-swagger'), swagger.options)
fastify.register(setSwaggerStats)

with

const swStats = require('swagger-stats')
const apiSpec = require('./swagger.json')
async function setSwaggerStats(fastify, opts) {
    await fastify.register(require('middie')) // or fastify-express is the same
    fastify.register(swStats.getFastifyPlugin, { swaggerSpec: apiSpec });
}

I also installed prom-client although I will be happy with the native dashboard.

http://localhost:3000/swagger-stats/ http://localhost:3000/swagger-stats/ui didn't show up (404)

It would be nice to provide {debug: true} option with some errors logged if this is feasible.

Thanks a lot !!!

ghost commented 2 years ago

Edit

maybe worth to note, my endpoint was set through options as either 127.0.0.1:3000 or 127.0.0.1 Also as I printed stats all are zeros:

setTimeout(() => {
   console.log(swStats.getCoreStats())
}, 10000);

and finally my swagger.json is "swagger":"2.0"

sv2 commented 2 years ago

To enable debug logging, please set env variable DEBUG=sws:*. Can you share output ?

ghost commented 2 years ago

Very nice, this is logging:

2022-03-24T15:20:49.898Z sws:apistats SWS:Initialize API:added get /home (/home) 2022-03-24T15:20:49.898Z sws:apistats SWS:Initialize API:added get /__ping_trans (/__ping_trans) 2022-03-24T15:20:49.899Z sws:apistats SWS:Initialize API:added get /i18n/{locale} (/i18n/:locale) 2022-03-24T15:20:49.899Z sws:apistats SWS:Initialize API:added get /login (/login) // a lot others 2022-03-24T15:20:49.904Z sws:apistats SWS:Initialize API:added get /game/ (/game/) 2022-03-24T15:20:49.904Z sws:apistats SWS:Initialize API:added get /sthtwnXLob/visitors (/sthtwnXLob/visitors) 2022-03-24T15:20:49.935Z sws:elastic Error getting version: {"errno":-4078,"code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":9200} worker 6620 died

Does it expect another service (Elastic-search here -- port 9200) ? I thought it is stand-alone and Kibana/ElasticSearch/Grafana/Prometheus all are optional.

I was using one of options provided in README, then I just used the swaggerSpec, and the error is nearly the same:

2022-03-24T15:29:18.918Z sws:elastic Elasticsearch url is invalid

The apps needs a DB, so I'm guessing, the used DB is ElasticSearch, and the only option...

ghost commented 2 years ago

In doc it seems optional:

Elasticsearch URL. If specified, enables storing of request response records in Elasticsearch. Default is empty (storing to Elasticsearch is disabled).

While in code, it is not (this commit)

Edit

I tried to dive in (although I would prefere not to add ElasticSearch into the stack), so I'm running:

ElasticSearch and Kibana versions 8.1 on Windows !!.

Dashboard is accessible and I set some agent (windows) and other example dashboards to explore more... everything is fine. Then setting:

{ 
  elasticsearch: 'http://127.0.0.1:9200',
  elasticsearchUsername: 'elastic',
  elasticsearchPassword: 'ujDSKDTPfP#####'
}

and I'm getting

sws:elastic Error getting version: {"code":"ECONNRESET"}

with: { url: 'http://127.0.0.1:9200', json: true, key: null, cert: null } { username: 'elastic', password: 'ujDSKDTPfP#####' }

I'm lost 😞

ghost commented 2 years ago

I removed token based authentication from Elastic and set it to basic (user/pass). Also removed SSL options, now my app bootstraps well; No error like before:

~4078,"code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":9200}~ ~worker 6620 died~

However, endpoints are still not found (404). I'm thinking it just doesn't work with Elastic 8.