Hypertest v2 Docs
HyperTest
  • Overview
    • How It Works?
  • SETUP GUIDE
    • Installation
      • Deploy HyperTest Server
      • Creating your first User
      • Adding your first service
      • Integrate SDK
        • Node.js
          • Node.js SDK with CJS
          • Node.js SDK with ESM
        • Java
    • Start a Test Run
      • CLI Login
      • Type References
      • Java
  • Interpreting Test Results
    • Test Results
    • Understanding Results Categories
    • Mock Not Found
    • AI Match Mocks
    • Accepting Changes
  • USER GUIDES
    • Node.js SDK
      • Limit memory usage
      • Supported NPM packages
      • Mock Dependencies Manually
      • Unmocking/Passing Through
      • Sampling and blocking requests
      • Manage Global Variables
      • Mocking Environment Variables
      • Tags
      • Set HTTP path patterns
      • Discard a test case(Request) while recording
      • Set Git Commit Hash
      • Code coverage based features
        • Continuous Coverage
        • Updating test coverage
        • Running post test deduplication
        • Only testing modified requests
        • Ignore differences for unmodified requests
      • Experimental flags
      • Manual Request
      • Only testing modified requests
      • Server hooks
    • Java SDK
      • Sampling and blocking requests
      • Mock Dependencies Manually
      • Tags
      • Unmocking/Passing Through
      • Code Coverage Setup and Report Generation
      • Supported Java packages
    • Build your own Docker Image
    • CLI Config
    • Ignoring Differences
      • Type References for Filter functions
  • Impact Features
    • Fast Mode
    • Code Coverage Report
    • Delete Recorded Requests
    • Inter Service Testing
  • Release History
    • Slack Integration
    • Version History
Powered by GitBook
On this page
  • Sampling
  • How it works
  • Paradigm 1 - Adaptive sampling
  • Paradigm 2 - Cool off time intensive requests
  • Paradigm 3 - Sampling rate
  • Using multiple paradigms together
  • Blocking requests
  1. USER GUIDES
  2. Node.js SDK

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 with this. There are three sampling paradigms in hypertest.

Paradigm 1 - Adaptive sampling

Under this paradigm we make a prediction if the next incoming request will be unique or a duplicate. This prediction is based on the coverage data of each request that we record. As we encounter less and less unique cases, the probability of recording a request decreases. If we encounter more unique cases the probability of recording adapts and goes up.

Code

htSdk.setSamplingConfig({
  http: [
    {
      path: '/user/signup',
      method: '*',
      useAdaptiveSampling: true,
    }
  ]
})

Paradigm 2 - Cool off time intensive requests

Under this paradigm, sdk stops recording for requests that take too long to execute. Maximum response time and the corresponding cool off period are configurable. The requests taking more than maximum response time are blocked for time mentioned in coolOffPeriod. So, the next time such a request comes it wont be recorded, decreasing your latency.

Code

htSdk.setSamplingConfig({
  http: [
    {
      path: '/user/signup',
      method: '*',
      coolOffPeriodMs: 10 * 1000,
      maxResponseTimeMs: 5000,
    }
  ]
})

Paradigm 3 - Sampling rate

Third 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.

Code

htSdk.setSamplingConfig({
  http: [
    {
      path: '/user/signup',
      method: '*',
      samplingRate: 0.65,
    }
  ]
})

Using multiple paradigms together

These three paradigms can be used together and are additive in nature.

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

You can provide a list of configs for a protocol, 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.

PreviousUnmocking/Passing ThroughNextManage Global Variables

Last updated 2 months ago