This repository has been archived by the owner on Jul 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
Recreate firebase user on password reset #685
Closed
Closed
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7a74ae6
Recreate firebase user on password reset\
whaught 258d285
redo flash
whaught 7453bd2
update for external reset too
whaught d4612ae
Metrics
whaught 0382dff
Merge remote-tracking branch 'upstream/main' into recreate-user
whaught a331e1d
shared metrics on context
whaught 8d2d634
remove from main
whaught 25f1b34
lower
whaught 7ad069a
unused context
whaught 48ada5a
return contexts
whaught e3b4cfa
scoping
whaught 51eebda
err at main
whaught 671bd94
Merge remote-tracking branch 'upstream/main' into recreate-user
whaught c1a032d
move metrics to the db
whaught bc6959f
revert main
whaught 3b37ad8
spacing
whaught 14c859a
space
whaught b9455b5
merge changes
whaught 44fc5d5
Merge remote-tracking branch 'upstream/main' into recreate-user
whaught File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,62 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package controller | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/google/exposure-notifications-verification-server/pkg/observability" | ||
|
||
"go.opencensus.io/stats" | ||
"go.opencensus.io/stats/view" | ||
"go.opencensus.io/tag" | ||
) | ||
|
||
const contextKeyMetrics = contextKey("controllerMetricsKey") | ||
|
||
var MetricPrefix = observability.MetricRoot + "/server/shared" | ||
|
||
type Metrics struct { | ||
FirebaseRecreates *stats.Int64Measure | ||
} | ||
|
||
func MetricsFromContext(ctx context.Context) (context.Context, *Metrics, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've removed all that and shoved it into the database per our conversation. I think sharing context makes sense but @mikehelmick prefers the tighter scoping in main.go |
||
v := ctx.Value(contextKeyMetrics) | ||
if v == nil { | ||
return registerMetrics(ctx) | ||
} | ||
|
||
if m, ok := v.(*Metrics); ok { | ||
return ctx, m, nil | ||
} | ||
return registerMetrics(ctx) | ||
} | ||
|
||
func registerMetrics(ctx context.Context) (context.Context, *Metrics, error) { | ||
mFirebaseRecreates := stats.Int64(MetricPrefix+"/fb_recreate", "recreation of firebase users", stats.UnitDimensionless) | ||
if err := view.Register(&view.View{ | ||
Name: MetricPrefix + "/fb_recreate_count", | ||
Measure: mFirebaseRecreates, | ||
Description: "The count of firebase account recreations", | ||
TagKeys: []tag.Key{observability.RealmTagKey}, | ||
Aggregation: view.Count(), | ||
}); err != nil { | ||
return ctx, nil, fmt.Errorf("stat view registration failure: %w", err) | ||
} | ||
|
||
metrics := &Metrics{FirebaseRecreates: mFirebaseRecreates} | ||
return context.WithValue(ctx, contextKeyMetrics, metrics), metrics, nil | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't love the dependency through context - it now implies an ordering between controller creation.
I still think there are other solutions that don't require that ordering / dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by ordering? This is lazily initialized as a singleton on context, if the controller can't find it on context, it gets created. Controllers can be organized in any order (the first one will create)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it requires that everyone who calls it shares a context though, otherwise it will be created twice.
that may be OK in opencensus - I'm not positive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think OC actually requires you to use the ctx - all the data is stored on the ctx