slanatech/swagger-stats

Prevent tracking of specific routes

jimmyjiji opened this issue · 6 comments

Hello!

If I create a swagger doc to track specific URL, let's give an example I want to track

/iwanttotrack/certainIssue

But this URL falls under a routing system that does

/iwanttotrack/:issue

As of now, swagger-stats tracks both. Is there a way that I can prevent the tracking of the latter route and only track the specific URL that I want it to track?

Thanks!

sv2 commented

Hi ! Could you kindly elaborate more on your scenarios ? I'd like to get a better sense of what kind of options to put in place to enable configurable tracking of endpoints ... for example, may consider introducing option to enable/disable tracking of all endpoints that are not in swagger, or explicitly specify an array of endpoints to track in options ... any details on your specific needs will help !

Thanks for getting back to me!
I was thinking about having the option to enable/disable tracking of all endpoints that are not in swagger. The reason being is that I have two endpoints for example which are routed the same way. I have route 1 which would be:

/iwanttotrack/issue1

and route 2 which I also want to track which would be

/iwanttotrack/issue2.

Currently, both hits to these endpoints show up in swagger-stats as:

/iwanttotrack/:issue.

I was hoping there would be an option to separate it out specifically as I wanted to track which of the two issues issue1 or issue2 would be hit more often.

sv2 commented

Thanks! Could you give me a sample how /iwanttotrack/issue1 is defined in your swagger spec ?

As of now it's a very simple definition

  "paths": {
    "/iwanttotrack/issue1": {
      "get": {
        "summary": "issue",
        "description": "This operation will get the issue",
        "responses": {
          "200": {
            "description": "The path is retrieved successfully."
          },
          "304": {
            "description": "The path is redirected successfully"
          }
        }
      }
    }
  },
    "/iwanttotrack/issue2": {
      "get": {
        "summary": "issue",
        "description": "This operation will get the issue",
        "responses": {
          "200": {
            "description": "The path is retrieved successfully."
          },
          "304": {
            "description": "The path is redirected successfully"
          }
        }
      }
  }

Nothing else to it.

sv2 commented

now you can specify option swaggerOnly={true|false}. When set to true, swagger-stats will only track API requests defined in swagger spec. Default is false. See example in auttest app:

app.use(swStats.getMiddleware({
    name: 'swagger-stats-authtest',
    version: '0.95.0',
    hostname: "hostname",
    ip: "127.0.0.1",
    swaggerSpec:swaggerSpec,
    swaggerOnly: true,
    uriPath: '/swagger-stats',
    durationBuckets: [10, 25, 50, 100, 200],
    requestSizeBuckets: [10, 25, 50, 100, 200],
    responseSizeBuckets: [10, 25, 50, 100, 200],
    apdexThreshold: 100,
    onResponseFinish: function(req,res,rrr){
        debug('onResponseFinish: %s', JSON.stringify(rrr));
    },
    authentication: true,
    sessionMaxAge: maxAge,
    onAuthenticate: function(req,username,password){
        // simple check for username and password
        if(username==='swagger-stats') {
            return ((username === 'swagger-stats') && (password === 'swagger-stats'));
        } else if(username==='swagger-promise'){
            return new Promise(function(resolve) {
                setTimeout(function(){
                    resolve((username === 'swagger-promise') && (password === 'swagger-promise'));
                }, 1000);
            });
        }
        return false;
    }
}));

I don't believe this is solving the problem that the author of this issue described. However I also think that this tool should not do what he wants for reasons related to #34.