This repository has been archived by the owner on Jul 10, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce ApplicationSupport to parse application tags on agent startup
and also make every Invocation support method static.
- Loading branch information
İbrahim Gürses
committed
Nov 14, 2018
1 parent
f7462d7
commit e5c1037
Showing
8 changed files
with
110 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { envVariableKeys } from '../../Constants'; | ||
|
||
import ThundraLogger from '../../ThundraLogger'; | ||
|
||
class ApplicationSupport { | ||
static applicationTags: any = {}; | ||
|
||
static parseApplicationTags(): void { | ||
ApplicationSupport.applicationTags = {}; | ||
for (const key of Object.keys(process.env)) { | ||
if (key.startsWith(envVariableKeys.THUNDRA_APPLICATION_TAG_PROP_NAME_PREFIX)) { | ||
try { | ||
const propsKey = key.substring(envVariableKeys.THUNDRA_APPLICATION_TAG_PROP_NAME_PREFIX.length); | ||
const propsValue = process.env[key]; | ||
if (isNaN(parseFloat(propsValue))) { | ||
if (propsValue === 'true' || propsValue === 'false') { | ||
ApplicationSupport.applicationTags[propsKey] = propsValue === 'true' ? true : false; | ||
} else { | ||
ApplicationSupport.applicationTags[propsKey] = propsValue; | ||
} | ||
} else { | ||
ApplicationSupport.applicationTags[propsKey] = parseFloat(propsValue); | ||
} | ||
} catch (ex) { | ||
ThundraLogger.getInstance().error(`Cannot parse application tag ${key}`); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default ApplicationSupport; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
import ApplicationSupport from '../../dist/plugins/support/ApplicationSupport'; | ||
|
||
describe('addApplicationTags', () => { | ||
const THUNDRA_APPLICATION_TAG_PROP_NAME_PREFIX = 'thundra_agent_lambda_application_tag_'; | ||
process.env[THUNDRA_APPLICATION_TAG_PROP_NAME_PREFIX + 'tag1'] = '5'; | ||
process.env[THUNDRA_APPLICATION_TAG_PROP_NAME_PREFIX + 'tag2'] = 'true'; | ||
process.env[THUNDRA_APPLICATION_TAG_PROP_NAME_PREFIX + 'tag3'] = 'false'; | ||
process.env[THUNDRA_APPLICATION_TAG_PROP_NAME_PREFIX + 'tag4'] = 'test value'; | ||
process.env[THUNDRA_APPLICATION_TAG_PROP_NAME_PREFIX + 'tag5'] = '3.5'; | ||
|
||
ApplicationSupport.parseApplicationTags(); | ||
|
||
it('should parse application tags from environment variables', () => { | ||
expect(ApplicationSupport.applicationTags['tag1']).toBe(5); | ||
expect(ApplicationSupport.applicationTags['tag2']).toBe(true); | ||
expect(ApplicationSupport.applicationTags['tag3']).toBe(false); | ||
expect(ApplicationSupport.applicationTags['tag4']).toBe('test value'); | ||
expect(ApplicationSupport.applicationTags['tag5']).toBe(3.5); | ||
}); | ||
|
||
process.env[THUNDRA_APPLICATION_TAG_PROP_NAME_PREFIX + 'tag1'] = null; | ||
process.env[THUNDRA_APPLICATION_TAG_PROP_NAME_PREFIX + 'tag2'] = null; | ||
process.env[THUNDRA_APPLICATION_TAG_PROP_NAME_PREFIX + 'tag3'] = null; | ||
process.env[THUNDRA_APPLICATION_TAG_PROP_NAME_PREFIX + 'tag4'] = null; | ||
process.env[THUNDRA_APPLICATION_TAG_PROP_NAME_PREFIX + 'tag5'] = null; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters