Sampling and blocking requests

Sampling

How it works

It is possible that while using hypertest sdk the latency of your APIs increase. Hypertest provides a mechanism called sampling to deal wiith this. There are two ways by which hypertest sdk samples.

First is by telling the sdk to stop recording the requests for a certain cool off period. You tell us which requests should be sampled by providing a maximum response time. The requests taking more than maximum response time are marked to be sampled. So, the next time such a request comes it wont be recorded, decreasing your latency.

Second way is by specifying the sampling rate for requests. Example: A sampling rate of 65 percent would mean, out of all the requests roughly 65 percent would actually end up recorded, other 35 would be blocked.

These two methods can be used together and are additive in nature.

Code

htSdk.setSamplingConfig({
  http: [
    {
      path: '*',
      samplingRate: 1,
      coolOffPeriodMs: 10 * 1000,
      maxResponseTimeMs: 5000,
    },
    {
      path: '*',
      coolOffPeriodMs: 10 * 1000,
      maxResponseTimeMs: 5000,
    }
  ],
  grpc: [
    {
      service: 'Service1.greeter',
      method: 'SayHello',
      coolOffPeriodMs: 10 * 1000,
      maxResponseTimeMs: 5000
    }
  ]
});

You can provide a list of configs, each targetting a group of requests. The sdk starts matching the requests from top to bottom. There exists a default config for sampling at the bottom of the list by default that looks like this. It matches with all the requests, providing a fallback in case no configs match.

{
  path: '*',
  method: '*',
  samplingRate: 1,
  maxResponseTimeMs: 10 * 1000,
  coolOffPeriodMs: 60 * 1000
}

Blocking requests

Hypertest sdk allows you to specify a config to stop recording certain requests. You can specify the method and the path of the request you want to be be blocked.

htSdk.setBlockRequestsConfig({
  http: [
    {
      path: '/sampling/blocking'
    },
    {
      path: '/test/blocking',
      method: '*'
    },
    {
      path: /sampling\/blocking/,
      method: 'put'
    },
    {
      path: '/sampling/:id'
    },
    {
      path: '/sampling/{id}'
    }
  ],
  grpc: [
    {
      service: 'helloworld.Greeter',
      method: '*'
    }
  ]
})
  • Method is a string that takes '*' or any valid http verb as value. It is case insensitive. If you dont specify it, it is assumed to be '*' which matches it with all the possible verbs

  • Path can take the absolute request path or a regex or the cluster path of the http request.

Last updated