-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds performance monitoring triggers to v2 alerts (#1223)
* rebasing master * add return to app distro * merge changelog * yank trace * add alert type to index * add link into tsdoc * fix get opts * linter * lineup with master * linter * adding logic to convert a payload to api council spec * fix wording of optional fields
- Loading branch information
1 parent
7783ae6
commit c18e832
Showing
13 changed files
with
410 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Add performance monitoring triggers to v2 alerts (#1223). |
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,168 @@ | ||
import { expect } from 'chai'; | ||
import * as alerts from '../../../../src/v2/providers/alerts'; | ||
import * as performance from '../../../../src/v2/providers/alerts/performance'; | ||
import { FULL_ENDPOINT, FULL_OPTIONS } from '../fixtures'; | ||
|
||
const APPID = '123456789'; | ||
const myHandler = () => 42; | ||
|
||
const APP_EVENT_FILTER = { | ||
appid: APPID, | ||
}; | ||
|
||
describe('performance', () => { | ||
describe('onThresholdAlertPublished', () => { | ||
it('should create a function with alertType & appId', () => { | ||
const func = performance.onThresholdAlertPublished(APPID, myHandler); | ||
|
||
expect(func.__endpoint).to.deep.equal({ | ||
platform: 'gcfv2', | ||
labels: {}, | ||
eventTrigger: { | ||
eventType: alerts.eventType, | ||
eventFilters: { | ||
...APP_EVENT_FILTER, | ||
alerttype: performance.thresholdAlert, | ||
}, | ||
retry: false, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should create a function with opts', () => { | ||
const func = performance.onThresholdAlertPublished( | ||
{ ...FULL_OPTIONS }, | ||
myHandler | ||
); | ||
|
||
expect(func.__endpoint).to.deep.equal({ | ||
...FULL_ENDPOINT, | ||
eventTrigger: { | ||
eventType: alerts.eventType, | ||
eventFilters: { | ||
alerttype: performance.thresholdAlert, | ||
}, | ||
retry: false, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should create a function with appid in opts', () => { | ||
const func = performance.onThresholdAlertPublished( | ||
{ ...FULL_OPTIONS, appId: APPID }, | ||
myHandler | ||
); | ||
|
||
expect(func.__endpoint).to.deep.equal({ | ||
...FULL_ENDPOINT, | ||
eventTrigger: { | ||
eventType: alerts.eventType, | ||
eventFilters: { | ||
...APP_EVENT_FILTER, | ||
alerttype: performance.thresholdAlert, | ||
}, | ||
retry: false, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should create a function without opts or appId', () => { | ||
const func = performance.onThresholdAlertPublished(myHandler); | ||
|
||
expect(func.__endpoint).to.deep.equal({ | ||
platform: 'gcfv2', | ||
labels: {}, | ||
eventTrigger: { | ||
eventType: alerts.eventType, | ||
eventFilters: { | ||
alerttype: performance.thresholdAlert, | ||
}, | ||
retry: false, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should create a function with a run method', () => { | ||
const func = performance.onThresholdAlertPublished( | ||
APPID, | ||
(event) => event | ||
); | ||
|
||
const res = func.run('input' as any); | ||
|
||
expect(res).to.equal('input'); | ||
}); | ||
}); | ||
|
||
describe('getOptsAndApp', () => { | ||
it('should parse a string', () => { | ||
const [opts, appId] = performance.getOptsAndApp(APPID); | ||
|
||
expect(opts).to.deep.equal({}); | ||
expect(appId).to.equal(APPID); | ||
}); | ||
|
||
it('should parse an options object without appId', () => { | ||
const myOpts: performance.PerformanceOptions = { | ||
region: 'us-west1', | ||
}; | ||
|
||
const [opts, appId] = performance.getOptsAndApp(myOpts); | ||
|
||
expect(opts).to.deep.equal({ region: 'us-west1' }); | ||
expect(appId).to.be.undefined; | ||
}); | ||
|
||
it('should parse an options object with appId', () => { | ||
const myOpts: performance.PerformanceOptions = { | ||
appId: APPID, | ||
region: 'us-west1', | ||
}; | ||
|
||
const [opts, appId] = performance.getOptsAndApp(myOpts); | ||
|
||
expect(opts).to.deep.equal({ region: 'us-west1' }); | ||
expect(appId).to.equal(APPID); | ||
}); | ||
}); | ||
|
||
describe('convertPayload', () => { | ||
it('should return the same payload', () => { | ||
const payload = { | ||
a: 'b', | ||
conditionPercentile: 23, | ||
appVersion: '3', | ||
}; | ||
|
||
const convertedPayload = performance.convertPayload(payload as any); | ||
|
||
expect(convertedPayload).to.deep.eq(payload); | ||
}); | ||
|
||
it('should return the same payload if the fields are undefined', () => { | ||
const payload = { | ||
a: 'b', | ||
}; | ||
|
||
const convertedPayload = performance.convertPayload(payload as any); | ||
|
||
expect(convertedPayload).to.deep.eq({ | ||
a: 'b', | ||
}); | ||
}); | ||
|
||
it('should remove fields', () => { | ||
const payload = { | ||
a: 'b', | ||
conditionPercentile: 0, | ||
appVersion: '', | ||
}; | ||
|
||
const convertedPayload = performance.convertPayload(payload as any); | ||
|
||
expect(convertedPayload).to.deep.eq({ | ||
a: 'b', | ||
}); | ||
}); | ||
}); | ||
}); |
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
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
Oops, something went wrong.