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

Prevent tracking of specific routes #36

Closed
jimmyjiji opened this issue Apr 12, 2018 · 6 comments
Closed

Prevent tracking of specific routes #36

jimmyjiji opened this issue Apr 12, 2018 · 6 comments
Assignees

Comments

@jimmyjiji
Copy link

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 sv2 self-assigned this Apr 12, 2018
@sv2
Copy link
Collaborator

sv2 commented Apr 12, 2018

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 !

@jimmyjiji
Copy link
Author

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
Copy link
Collaborator

sv2 commented Apr 12, 2018

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

@jimmyjiji
Copy link
Author

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
Copy link
Collaborator

sv2 commented May 1, 2018

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;
    }
}));

@sv2 sv2 closed this as completed in 7723d26 May 1, 2018
@briankinney
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants