Skip to content
This repository has been archived by the owner. It is now read-only.

refactor(signin): Add support for sending flow metrics in email #1593

Merged
merged 7 commits into from Jan 4, 2017

Conversation

@vbudhram
Copy link
Contributor

@vbudhram vbudhram commented Dec 16, 2016

2nd part of #1425

@vbudhram vbudhram added the WIP label Dec 16, 2016
@vbudhram vbudhram self-assigned this Dec 16, 2016
// Log flow metrics if `flowId` and `flowBeginTime` specified in headers
const flowId = getHeaderValue('X-Flow-Id', message)
const flowBeginTime = getHeaderValue('X-Flow-Begin-Time', message)
if (flowId && flowBeginTime) {

This comment has been minimized.

@vladikoff

vladikoff Dec 19, 2016
Contributor

might need to validate that those values are in proper format in the future.

This comment has been minimized.

@vladikoff

vladikoff Dec 19, 2016
Contributor

actually, I guess these are coming from AWS, so it should be safe enough.

flow_time: (currentTime <= flowBeginTime) ? 0 : (currentTime - flowBeginTime)
}

log.info('flowEvent', flowEventInfo)

This comment has been minimized.

@vladikoff

vladikoff Dec 19, 2016
Contributor

need to make sure that the flowEvent importer looks at bouncer logs

This comment has been minimized.

@philbooth

philbooth Dec 19, 2016
Contributor

Indeed we will.

@vbudhram, when it's time, you probably want to chat to @whd about this in IRC, and/or raise a bug with product set to Cloud Services and component set to Metrics: Pipeline. See, for example, this bug as an example of something similar-ish.

@vbudhram
Copy link
Contributor Author

@vbudhram vbudhram commented Dec 19, 2016

@philbooth Mind giving this a look over?

I can update shrinkwrap to point to mailer once mozilla/fxa-auth-mailer#241 has merged.

event: eventName,
time: currentTime,
flow_id: flowId,
flow_time: (currentTime <= flowBeginTime) ? 0 : (currentTime - flowBeginTime)

This comment has been minimized.

@philbooth

philbooth Dec 19, 2016
Contributor

Rather than try to normalise this, I'd rather drop the event if currentTime is less than flowBeginTime. There is no legitimate situation in which that would be okay.

This comment has been minimized.

@philbooth

philbooth Dec 19, 2016
Contributor

Alternatively, if we are confident that will never happen because flowBeginTime is ultimately the one we already validated on entry to the auth server, then just don't bother checking it all. But having the check like this sends a misleading message to future readers I think.

This comment has been minimized.

@vbudhram

vbudhram Dec 20, 2016
Author Contributor

@philbooth Opted for dropping if currentTime < flowBeginTime

const flowBeginTime = getHeaderValue('X-Flow-Begin-Time', message)
if (flowId && flowBeginTime) {
const eventName = 'email.' + templateName + '.bounced'
const currentTime = Date.now()

This comment has been minimized.

@philbooth

philbooth Dec 19, 2016
Contributor

Can we set this right at the top of the function, just to be as precise as possible about the time of the bounce(s)?

This comment has been minimized.

@philbooth

philbooth Dec 19, 2016
Contributor

(I mean at the top of the parent function, not the top of the iteratee)

flowBeginTime = request.payload.metricsContext.flowBeginTime
}

request.validateMetricsContext()

This comment has been minimized.

@philbooth

philbooth Dec 19, 2016
Contributor

We should move this call to validateMetricsContext before we store flowId and flowBeginTime, otherwise we'll emit events containing bad data.

flow_time: (currentTime <= flowBeginTime) ? 0 : (currentTime - flowBeginTime)
}

log.info('flowEvent', flowEventInfo)

This comment has been minimized.

@philbooth

philbooth Dec 19, 2016
Contributor

I get why you opted for this approach, because it saves the hassle of faking the request object required to call log.flowEvent directly. But I wonder whether it is worth moving this call and the preceding assignment to flowEventInfo into a function inside lib/log.js?

I have a slight concern that we're doing the same thing in two places, albeit it's not a huge amount. If the current log.flowEvent was renamed to something along the lines of log.flowEventFromRequest, it could call log.flowEvent to do this stuff and your code could call it too.

What do you think, worth it or am I dreaming up imaginary obstacles?

This comment has been minimized.

@seanmonstar

seanmonstar Dec 20, 2016
Member

I agree with @philbooth, I think we probably want to instead call log.flowEvent, so that we have this logic in only 1 place. If it's cumbersome to create a fake request, that probably means we should update log.flowEvent to accept an alternative or easier structure.

This comment has been minimized.

@vbudhram

vbudhram Dec 20, 2016
Author Contributor

I think it is worthwhile to do both, but probably as a follow on issue/PR as to not clutter this one up too much?

This comment has been minimized.

@philbooth

philbooth Dec 20, 2016
Contributor

...as a follow on issue/PR as to not clutter this one up too much...

I'm totes okay with that, as long as we get the issue opened before this is merged. Otherwise we might forget.

This comment has been minimized.

@vbudhram

vbudhram Dec 20, 2016
Author Contributor

Woot! Made #1597

@philbooth
Copy link
Contributor

@philbooth philbooth commented Dec 19, 2016

@vbudhram, I've left some inline comments that need addressing but other than those I'm r+, nice one!

@@ -111,16 +113,18 @@ module.exports = function (log, error) {
// Log flow metrics if `flowId` and `flowBeginTime` specified in headers
const flowId = getHeaderValue('X-Flow-Id', message)
const flowBeginTime = getHeaderValue('X-Flow-Begin-Time', message)
if (flowId && flowBeginTime) {
const elapsedTime = currentTime - flowBeginTime

This comment has been minimized.

@vladikoff

vladikoff Dec 20, 2016
Contributor

sweeet!

const eventName = 'email.' + templateName + '.bounced'

// Flow events have a specific event and structure that must be emitted.
// Ref: https://github.com/mozilla/fxa-auth-server/blob/master/lib/metrics/context.js#L122

This comment has been minimized.

@philbooth

philbooth Dec 20, 2016
Contributor

Just a note on this comment, at some point lib/metrics/context.js will change then the line number will be wrong. Maybe just mention the file and function name or something?

const elapsedTime = currentTime - flowBeginTime

if (flowId && flowBeginTime && (elapsedTime > 0)) {
const eventName = 'email.' + templateName + '.bounced'

This comment has been minimized.

@philbooth

philbooth Dec 20, 2016
Contributor

Would this be cleaner with a template string?

const eventName = `email.${templateName}.bounced`
@vbudhram
Copy link
Contributor Author

@vbudhram vbudhram commented Dec 22, 2016

@philbooth Made updates you recommended and added changes to dynamically generate flow data in tests. I also update my refactor issue, #1597, to better expand generating mock flow data. Mind one more glance over before merge?

@rfk rfk force-pushed the add-flowId-email branch from 4bfc0a9 to 05307ea Jan 4, 2017
@rfk
Copy link
Member

@rfk rfk commented Jan 4, 2017

I've rebased and force-pushed this to fix the merge conflict, will merge once travis says it's OK

@rfk rfk merged commit 6955261 into master Jan 4, 2017
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@rfk rfk removed the waffle:review label Jan 4, 2017
@vbudhram vbudhram deleted the add-flowId-email branch Jan 24, 2017
@rfk rfk added this to the FxA-41:signin funnel metrics milestone Jan 25, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants