Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Disable warmup support by default and make it enabled via config options
Browse files Browse the repository at this point in the history
  • Loading branch information
İbrahim Gürses committed Dec 10, 2018
1 parent 255fe2c commit 63d3f74
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -49,6 +49,7 @@ Check out the [configuration part](https://thundra.readme.io/docs/nodejs-configu
| Name | Type | Default Value |
|:----------------------------------------------------------------|:------:|:-------------:|
| thundra_apiKey | string | - |
| thundra_lambda_warmup_warmupAware | bool | false |
| thundra_agent_lambda_application_stage | string | empty |
| thundra_agent_lambda_application_domainName | string | API |
| thundra_agent_lambda_application_className | string | AWS-Lambda |
Expand Down
1 change: 1 addition & 0 deletions src/Constants.ts
Expand Up @@ -6,6 +6,7 @@ import RedisIntegration from './plugins/integrations/RedisIntegration';
import AWSIntegration from './plugins/integrations/AWSIntegration';

export const envVariableKeys = {
THUNDRA_LAMBDA_WARMUP_AWARE: 'thundra_lambda_warmup_warmupAware',
THUNDRA_APIKEY: 'thundra_apiKey',
THUNDRA_DISABLE: 'thundra_agent_lambda_disable',
THUNDRA_APPLICATION_STAGE: 'thundra_agent_lambda_application_stage',
Expand Down
8 changes: 6 additions & 2 deletions src/index.ts
Expand Up @@ -88,7 +88,6 @@ module.exports = (options: any) => {
});

const increaseRequestCount = () => pluginContext.requestCount += 1;
const warmupWrapper = ThundraWarmup(increaseRequestCount);

return (originalFunc: any) => {

Expand All @@ -107,7 +106,12 @@ module.exports = (options: any) => {
return thundraWrapper.invoke();
};

return warmupWrapper(thundraWrappedHandler);
if (config.warmupAware) {
const warmupWrapper = ThundraWarmup(increaseRequestCount);
return warmupWrapper(thundraWrappedHandler);
} else {
return thundraWrappedHandler;
}
};
};

Expand Down
3 changes: 3 additions & 0 deletions src/plugins/config/ThundraConfig.ts
Expand Up @@ -10,6 +10,7 @@ const koalas = require('koalas');
class ThundraConfig {

trustAllCert: boolean;
warmupAware: boolean;
apiKey: string;
disableThundra: boolean;
traceConfig: TraceConfig;
Expand All @@ -34,6 +35,8 @@ class ThundraConfig {
this.xrayConfig = new AwsXRayConfig(options.xrayConfig);
this.trustAllCert = koalas(Utils.getConfiguration(
envVariableKeys.THUNDRA_AGENT_LAMBDA_TRUST_ALL_CERTIFICATES), options.trustAllCert, false);
this.warmupAware = koalas(Utils.getConfiguration(envVariableKeys.THUNDRA_LAMBDA_WARMUP_AWARE) === 'true',
options.warmupAware, false);
}

}
Expand Down
22 changes: 21 additions & 1 deletion test/index.test.js
Expand Up @@ -149,7 +149,8 @@ describe('Thundra library', () => {
});
});

describe('when it is a warmup', () => {
describe('when it is a warmup and thundra_lambda_warmup_warmupAware is true', () => {
process.env.thundra_lambda_warmup_warmupAware = 'true';
const originalEvent = {};
const originalContext = {};
const originalCallback = jest.fn();
Expand All @@ -166,6 +167,25 @@ describe('Thundra library', () => {

});

describe('when it is a warmup and thundra_lambda_warmup_warmupAware is not set', () => {
delete process.env.thundra_lambda_warmup_warmupAware;

const originalEvent = {};
const originalContext = {};
const originalCallback = jest.fn();
const originalFunction = jest.fn(() => originalCallback());
const ThundraWrapper = Thundra({ apiKey: 'apiKey' });
const wrappedFunction = ThundraWrapper(originalFunction);
console['log'] = jest.fn();
jest.useFakeTimers();
wrappedFunction(originalEvent, originalContext, originalCallback);
jest.runAllTimers();
it('should invoke the function', () => {
expect(originalFunction).toBeCalled();
});

});

describe('Authorize All Certs', () => {
describe('enabled by config', () => {
delete process.env.thundra_agent_lambda_publish_report_rest_trustAllCertificates;
Expand Down

0 comments on commit 63d3f74

Please sign in to comment.