Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metrics: Add per adapter metric indicating when buyeruid was scrubbed #3623

Merged
merged 8 commits into from
Apr 16, 2024

Conversation

bsardo
Copy link
Collaborator

@bsardo bsardo commented Apr 11, 2024

No description provided.

@@ -560,6 +560,9 @@ type DisabledMetrics struct {
// that were created or reused.
AdapterConnectionMetrics bool `mapstructure:"adapter_connections_metrics"`

// True if we don't want to collect the per adapter buyer UID scrubbed metric
AdapterBuyerUIDScrubbed bool `mapstructure:"adapter_buyeruid_scrubbed"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add this field to config_test.go, with TestDefaults and TestFullConfig?

@@ -202,6 +205,9 @@ func (rs *requestSplitter) cleanOpenRTBRequests(ctx context.Context,
privacy.ScrubDeviceIDsIPsUserDemoExt(reqWrapper, ipConf, "eids", false)
}
}
if buyerUIDSet && reqWrapper.User.BuyerUID == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking, could this be re-written, removing the lines 191-194, and instead just put the conditions here:

if reqWrapper.User != nil && reqWrapper.User.BuyerUID != "" && reqWrapper.User.BuyerUID == "" {
	rs.me.RecordAdapterBuyerUIDScrubbed(bidderRequest.BidderCoreName)
}

What do you think about this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah if you look at your suggested snippet again you'll see that you're referencing reqWrapper.User.BuyerUID twice. The reason I wrote it the way I did is so I can capture reqWrapper.User.BuyerUID as buyerUIDSet before it is potentially overwritten by the scrubber logic.
I am then checking if the value was set and has since been cleared by the scrubber before logging the metric.
Does that make sense?

Comment on lines 805 to 820
description: "",
metricsDisabled: false,
adapterName: openrtb_ext.BidderName(adapter),
expectedCount: 1,
},
{
description: "",
metricsDisabled: false,
adapterName: fakeBidder,
expectedCount: 0,
},
{
description: "",
metricsDisabled: true,
adapterName: openrtb_ext.BidderName(adapter),
expectedCount: 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add descriptions for these tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added missing descriptions for this test and an old test that I used as a template for this. I also converted both to use t.Run.

@@ -952,6 +959,16 @@ func (m *Metrics) RecordRequestPrivacy(privacy metrics.PrivacyLabels) {
}
}

func (m *Metrics) RecordAdapterBuyerUIDScrubbed(adapterName openrtb_ext.BidderName) {
if m.metricsDisabled.AdapterGDPRRequestBlocked {
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to add a test to cover this return?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added coverage and fixed the incorrect condition here.

buyerUIDSet := false
if reqWrapper.User != nil && reqWrapper.User.BuyerUID != "" {
buyerUIDSet = true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

buyerUIDSet := reqWrapper.User != nil && reqWrapper.User.BuyerUID != ""?

@@ -202,6 +205,9 @@ func (rs *requestSplitter) cleanOpenRTBRequests(ctx context.Context,
privacy.ScrubDeviceIDsIPsUserDemoExt(reqWrapper, ipConf, "eids", false)
}
}
if buyerUIDSet && reqWrapper.User.BuyerUID == "" {
rs.me.RecordAdapterBuyerUIDScrubbed(bidderRequest.BidderCoreName)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This works. Alternatively, we could track a second bool buyerIDRemoved which is set true alongside calls to any of the above privacy.Scrub calls.

@@ -926,6 +931,21 @@ func (me *Metrics) RecordRequestPrivacy(privacy PrivacyLabels) {
}
}

func (me *Metrics) RecordAdapterBuyerUIDScrubbed(adapterName openrtb_ext.BidderName) {
adapterStr := string(adapterName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer adapterName.String()

AlexBVolcy
AlexBVolcy previously approved these changes Apr 12, 2024
Copy link
Contributor

@guscarreon guscarreon left a comment

Choose a reason for hiding this comment

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

In order for config values be read from environment variables, Viper needs a v.SetDefault entry (I don't recall why). Can we add a SetDefault() call?

890   // Set the default config values for the viper object we are using.
891   func SetupViper(v *viper.Viper, filename string, bidderInfos BidderInfos) {
892       if filename != "" {
893           v.SetConfigName(filename)
894 *-- 56 lines: v.AddConfigPath(".")-------------------------------------------------------
950       v.SetDefault("metrics.disabled_metrics.adapter_connections_metrics", true)
951       v.SetDefault("metrics.disabled_metrics.adapter_gdpr_request_blocked", false)
    +     v.SetDefault("metrics.disabled_metrics.adapter_buyeruid_scrubbed", false)
952       v.SetDefault("metrics.influxdb.host", "")
config/config.go

Also, for the sake of backwards consistency in terms of the extra resources PBS requires when Prometheus preloads one counter per adapter when adapter_buyeruid_scrubbed holds a value of false, should we default to true instead?

In my opinion, when users update their PBS instance, they shouldn't experience an extra resource demand unless they explicitly enable this new feature. Thoughts?

Copy link
Contributor

@guscarreon guscarreon left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants