Skip to content
This repository has been archived by the owner on Oct 17, 2020. It is now read-only.

Add instrumentation code for SSO #1003

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

Ashakibp
Copy link
Collaborator

@Ashakibp Ashakibp commented Aug 22, 2020

Current Behavior

Currently we do not fire off metrics for SSOs, the objective of this PR is to fire off events whenever someone uses SSO and partition it by provider.

For #695

Description

We used a base instrumentation struct and then an implementation for every provider to make it easier for metric names to be traced down. The factory method will automatically pull the correct provider.

@Ashakibp
Copy link
Collaborator Author

New Gopher here so feel free to roast me on styling. It would be greatly appreciated to describe why we follow specific guidelines

singleSignOn sso.SingleSignOn,
webFrontendURL string,
) router.Handle {
return func(w http.ResponseWriter, r *http.Request, params router.Params) {
i := instrumentationFactory.NewRequest()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
i := instrumentationFactory.NewRequest()
i := instrumentationFactory.NewHTTP(r)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are tracking HTTP traffic here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to prepare for distributed tracing in the future

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main difference that I see is that its extracting the location from the HTTP call, is this true?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ashakibp Exactly!

@@ -10,10 +11,14 @@ import (

// SSOSignIn redirects user to the sign in page.
func SSOSignIn(
instrumentationFactory request.InstrumentationFactory,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
instrumentationFactory request.InstrumentationFactory,
instrumentationFactory request.SSOInstrumentationFactory,

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this a bit further, are we trying to compose an instrumentationFactory within an SSOInstrumentationFactory?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ashakibp Nope. SSO sign in only depends on SSOInstrumentationFactory, which constructs instrumentation.SSO

singleSignOn sso.SingleSignOn,
webFrontendURL string,
) router.Handle {
return func(w http.ResponseWriter, r *http.Request, params router.Params) {
i := instrumentationFactory.NewRequest()
i.SSOSignIn(singleSignOn.GetMetricName())

token := getToken(params)
if singleSignOn.IsSignedIn(token) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to invoke the instructation method here to actually track data.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also after this code path, we track the user is redirected to the generated sign in link at line 27.

singleSignOn sso.SingleSignOn,
webFrontendURL string,
) router.Handle {
return func(w http.ResponseWriter, r *http.Request, params router.Params) {
i := instrumentationFactory.NewRequest()
i.SSOSignIn(singleSignOn.GetMetricName())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The correct InstrumentationFactory can be injected inside the caller of this function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instrumentation code should be decoupled from SSO so that we can change them independently

backend/app/adapter/routing/route.go Outdated Show resolved Hide resolved
backend/app/usecase/sso/sso.go Outdated Show resolved Hide resolved
backend/app/usecase/sso/sso_test.go Outdated Show resolved Hide resolved
backend/dep/provider/facebook.go Show resolved Hide resolved
backend/dep/provider/github.go Outdated Show resolved Hide resolved
backend/dep/provider/google.go Outdated Show resolved Hide resolved
…e-to-all-routes' into ashakibp-Add-instrumentation-code-to-all-routes
Copy link
Member

@arberiii arberiii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -10,10 +11,14 @@ import (

// SSOSignIn redirects user to the sign in page.
func SSOSignIn(
instrumentationFactory request.InstrumentationFactory,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ashakibp Nope. SSO sign in only depends on SSOInstrumentationFactory, which constructs instrumentation.SSO

singleSignOn sso.SingleSignOn,
webFrontendURL string,
) router.Handle {
return func(w http.ResponseWriter, r *http.Request, params router.Params) {
i := instrumentationFactory.NewRequest()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ashakibp Exactly!

backend/app/usecase/instrumentation/sso.go Outdated Show resolved Hide resolved
@pull-request-size pull-request-size bot added size/L and removed size/M labels Aug 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants