-
Notifications
You must be signed in to change notification settings - Fork 749
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 for TCF 2 adoption #1360
Merged
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4b3b68e
Metrics for TCF 2 adapotion
hhhjort 95d5566
resolves merge conflicts
hhhjort 076c161
refactor metric names
hhhjort 25bdc49
Clarifies metric description
hhhjort 8144622
Adds a preload for tcf metrics.
hhhjort 5e46a52
Move TCF metrics more in line with other metrics implementaion
hhhjort b3737f7
Some more clarity/hardening around TCF version label values
hhhjort 7259297
fixes typo
hhhjort 3b76bde
Explicityly calls out the key value
hhhjort bfa680f
Adds a layer of abstraction to get TCF metrics more in line with othe…
hhhjort 3c56839
Some safety around the influx record function
hhhjort 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
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 |
---|---|---|
|
@@ -106,3 +106,8 @@ func (me *MetricsEngineMock) RecordRequestQueueTime(success bool, requestType Re | |
func (me *MetricsEngineMock) RecordTimeoutNotice(success bool) { | ||
me.Called(success) | ||
} | ||
|
||
// RecordTCF mock | ||
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. Typo: RecordTCFReq mock |
||
func (me *MetricsEngineMock) RecordTCFReq(version int) { | ||
me.Called(version) | ||
} |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package prometheusmetrics | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"time" | ||
|
||
|
@@ -28,7 +29,8 @@ type Metrics struct { | |
requestsWithoutCookie *prometheus.CounterVec | ||
storedImpressionsCacheResult *prometheus.CounterVec | ||
storedRequestCacheResult *prometheus.CounterVec | ||
timeout_notifications *prometheus.CounterVec | ||
timeoutNotifications *prometheus.CounterVec | ||
tcfMetrics *prometheus.CounterVec | ||
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. Can we please call this |
||
|
||
// Adapter Metrics | ||
adapterBids *prometheus.CounterVec | ||
|
@@ -63,6 +65,7 @@ const ( | |
requestStatusLabel = "request_status" | ||
requestTypeLabel = "request_type" | ||
successLabel = "success" | ||
versionLabel = "version" | ||
) | ||
|
||
const ( | ||
|
@@ -85,6 +88,11 @@ const ( | |
requestFailed = "failed" | ||
) | ||
|
||
const ( | ||
sourceLabel = "source" | ||
sourceRequest = "request" | ||
) | ||
|
||
// NewMetrics initializes a new Prometheus metrics instance with preloaded label values. | ||
func NewMetrics(cfg config.PrometheusMetrics) *Metrics { | ||
requestTimeBuckets := []float64{0.05, 0.1, 0.15, 0.20, 0.25, 0.3, 0.4, 0.5, 0.75, 1} | ||
|
@@ -153,11 +161,16 @@ func NewMetrics(cfg config.PrometheusMetrics) *Metrics { | |
"Count of stored request cache requests attempts by hits or miss.", | ||
[]string{cacheResultLabel}) | ||
|
||
metrics.timeout_notifications = newCounter(cfg, metrics.Registry, | ||
metrics.timeoutNotifications = newCounter(cfg, metrics.Registry, | ||
"timeout_notification", | ||
"Count of timeout notifications triggered, and if they were successfully sent.", | ||
[]string{successLabel}) | ||
|
||
metrics.tcfMetrics = newCounter(cfg, metrics.Registry, | ||
"privacy_tcf", | ||
hhhjort marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"Count of TCF versions for requests where GDPR was enforced.", | ||
[]string{versionLabel, sourceLabel}) | ||
|
||
metrics.adapterBids = newCounter(cfg, metrics.Registry, | ||
"adapter_bids", | ||
"Count of bids labeled by adapter and markup delivery type (adm or nurl).", | ||
|
@@ -412,12 +425,23 @@ func (m *Metrics) RecordRequestQueueTime(success bool, requestType pbsmetrics.Re | |
|
||
func (m *Metrics) RecordTimeoutNotice(success bool) { | ||
if success { | ||
m.timeout_notifications.With(prometheus.Labels{ | ||
m.timeoutNotifications.With(prometheus.Labels{ | ||
successLabel: requestSuccessful, | ||
}).Inc() | ||
} else { | ||
m.timeout_notifications.With(prometheus.Labels{ | ||
m.timeoutNotifications.With(prometheus.Labels{ | ||
successLabel: requestFailed, | ||
}).Inc() | ||
} | ||
} | ||
|
||
func (m *Metrics) RecordTCFReq(version int) { | ||
var value string = "err" | ||
if version > 0 { | ||
value = fmt.Sprintf("v%d", version) | ||
} | ||
m.tcfMetrics.With(prometheus.Labels{ | ||
versionLabel: value, | ||
sourceLabel: sourceRequest, | ||
}).Inc() | ||
} |
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
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.
Cool. So we're logging when enforcement is in play, but not if the enforcement resulted in action. Privacy enforcement still could be avoided for some bidders depending on permission setup. The same will soon be true for CCPA. I don't have a good suggestion here, just wanted to call it out.