Skip to content

Commit

Permalink
UOE-10822: Prometheus Stat for Bid Recovery (#851)
Browse files Browse the repository at this point in the history
* stat for bid recovery

* change buckets

* introduce new stat
  • Loading branch information
pm-saurabh-narkhede authored Sep 16, 2024
1 parent cb7dca4 commit 5d3b3de
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 0 deletions.
14 changes: 14 additions & 0 deletions modules/pubmatic/openwrap/metrics/config/multimetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,17 @@ func (me *MultiMetricsEngine) RecordSignalDataStatus(pubid, profileid, signalTyp
thisME.RecordSignalDataStatus(pubid, profileid, signalType)
}
}

// RecordBidRecoveryStatus across all engines
func (me *MultiMetricsEngine) RecordBidRecoveryStatus(publisher, profile string, success bool) {
for _, thisME := range *me {
thisME.RecordBidRecoveryStatus(publisher, profile, success)
}
}

// RecordBidRecoveryResponseTime across all engines
func (me *MultiMetricsEngine) RecordBidRecoveryResponseTime(publisher, profile string, responseTime time.Duration) {
for _, thisME := range *me {
thisME.RecordBidRecoveryResponseTime(publisher, profile, responseTime)
}
}
4 changes: 4 additions & 0 deletions modules/pubmatic/openwrap/metrics/config/multimetrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ func TestRecordFunctionForMultiMetricsEngine(t *testing.T) {
mockEngine.EXPECT().RecordOWServerPanic("endpoint", "methodName", "nodeName", "podName")
mockEngine.EXPECT().RecordAmpVideoRequests("pubid", "profileid")
mockEngine.EXPECT().RecordAmpVideoResponses("pubid", "profileid")
mockEngine.EXPECT().RecordBidRecoveryStatus(publisher, profile, true)
mockEngine.EXPECT().RecordBidRecoveryResponseTime(publisher, profile, time.Duration(200))

// create the multi-metric engine
multiMetricEngine := MultiMetricsEngine{}
Expand Down Expand Up @@ -291,4 +293,6 @@ func TestRecordFunctionForMultiMetricsEngine(t *testing.T) {
multiMetricEngine.RecordOWServerPanic("endpoint", "methodName", "nodeName", "podName")
multiMetricEngine.RecordAmpVideoRequests("pubid", "profileid")
multiMetricEngine.RecordAmpVideoResponses("pubid", "profileid")
multiMetricEngine.RecordBidRecoveryStatus(publisher, profile, true)
multiMetricEngine.RecordBidRecoveryResponseTime(publisher, profile, time.Duration(200))
}
2 changes: 2 additions & 0 deletions modules/pubmatic/openwrap/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type MetricsEngine interface {
RecordPublisherRequests(endpoint string, publisher string, platform string)
RecordReqImpsWithContentCount(publisher, contentType string)
RecordInjectTrackerErrorCount(adformat, publisher, partner string)
RecordBidRecoveryStatus(publisher, profile string, success bool)
RecordBidRecoveryResponseTime(publisher, profile string, responseTime time.Duration)

// not-captured in openwrap module, dont provide enough insights
RecordPBSAuctionRequestsStats()
Expand Down
24 changes: 24 additions & 0 deletions modules/pubmatic/openwrap/metrics/mock/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions modules/pubmatic/openwrap/metrics/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type Metrics struct {
pubNoBidResponseErrors *prometheus.CounterVec
pubResponseTime *prometheus.HistogramVec
pubImpsWithContent *prometheus.CounterVec
pubBidRecoveryStatus *prometheus.CounterVec
pubBidRecoveryTime *prometheus.HistogramVec

// publisher-partner-platform level metrics
pubPartnerPlatformRequests *prometheus.CounterVec
Expand Down Expand Up @@ -360,6 +362,19 @@ func newMetrics(cfg *config.PrometheusMetrics, promRegistry *prometheus.Registry
[]string{pubIdLabel, profileIDLabel},
)

metrics.pubBidRecoveryTime = newHistogramVec(cfg, promRegistry,
"bid_recovery_response_time",
"Total time taken by request for secondary auction in ms at publisher profile level.",
[]string{pubIDLabel, profileIDLabel},
[]float64{100, 200, 300, 400},
)

metrics.pubBidRecoveryStatus = newCounter(cfg, promRegistry,
"bid_recovery_response_status",
"Count bid recovery status for secondary auction",
[]string{pubIDLabel, profileIDLabel, successLabel},
)

newSSHBMetrics(&metrics, cfg, promRegistry)

return &metrics
Expand Down Expand Up @@ -680,3 +695,18 @@ func (m *Metrics) RecordPrebidCacheRequestTime(success bool, length time.Duratio
successLabel: strconv.FormatBool(success),
}).Observe(float64(length.Milliseconds()))
}

func (m *Metrics) RecordBidRecoveryStatus(publisherID, profileID string, success bool) {
m.pubBidRecoveryStatus.With(prometheus.Labels{
pubIDLabel: publisherID,
profileIDLabel: profileID,
successLabel: strconv.FormatBool(success),
}).Inc()
}

func (m *Metrics) RecordBidRecoveryResponseTime(publisherID, profileID string, responseTime time.Duration) {
m.pubBidRecoveryTime.With(prometheus.Labels{
pubIDLabel: publisherID,
profileIDLabel: profileID,
}).Observe(float64(responseTime.Milliseconds()))
}
24 changes: 24 additions & 0 deletions modules/pubmatic/openwrap/metrics/prometheus/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,30 @@ func TestRecordAdruleValidationFailure(t *testing.T) {
})
}

func TestRecordBidRecoveryStatus(t *testing.T) {
m := createMetricsForTesting()

m.RecordBidRecoveryStatus("5890", "123", true)

expectedCount := float64(1)
assertCounterVecValue(t, "", "bid_recovery_response_status", m.pubBidRecoveryStatus,
expectedCount, prometheus.Labels{
pubIDLabel: "5890",
profileIDLabel: "123",
successLabel: "true",
})
}

func TestRecordBidRecoveryResponseTime(t *testing.T) {
m := createMetricsForTesting()

m.RecordBidRecoveryResponseTime("5890", "12345", time.Duration(70)*time.Millisecond)
m.RecordBidRecoveryResponseTime("5890", "12345", time.Duration(130)*time.Millisecond)
resultingHistogram := getHistogramFromHistogramVecByTwoKeys(m.pubBidRecoveryTime,
pubIDLabel, "5890", profileIDLabel, "12345")
assertHistogram(t, "bid_recovery_response_time", resultingHistogram, 2, 200)
}

func getHistogramFromHistogramVec(histogram *prometheus.HistogramVec, labelKey, labelValue string) dto.Histogram {
var result dto.Histogram
processMetrics(histogram, func(m dto.Metric) {
Expand Down
3 changes: 3 additions & 0 deletions modules/pubmatic/openwrap/metrics/stats/tcp_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,5 +350,8 @@ func (st *StatsTCP) RecordAdruleEnabled(pubId, profId string)
func (st *StatsTCP) RecordAdruleValidationFailure(pubId, profId string) {}
func (st *StatsTCP) RecordSignalDataStatus(pubid, profileid, signalType string) {}
func (st *StatsTCP) RecordPrebidCacheRequestTime(success bool, length time.Duration) {}
func (st *StatsTCP) RecordBidRecoveryStatus(pubID string, profile string, success bool) {}
func (st *StatsTCP) RecordBidRecoveryResponseTime(pubID string, profile string, responseTime time.Duration) {
}
func (st *StatsTCP) RecordPrebidAuctionBidResponse(publisher string, partnerName string, bidderCode string, adapterCode string) {
}

0 comments on commit 5d3b3de

Please sign in to comment.