Skip to content

Commit

Permalink
Merge pull request #832 from PubMatic-OpenWrap/master
Browse files Browse the repository at this point in the history
Fix: Panic fast XML (#831)
  • Loading branch information
PubMatic-OpenWrap authored Jul 3, 2024
2 parents 11a5a46 + 4dbec9f commit cc2d79a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
4 changes: 2 additions & 2 deletions metrics/prometheus/prometheus_ow.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ func (m *OWMetrics) RecordXMLParserResponseTime(parser string, method string, bi
// RecordVastVersion record the count of vast version labelled by bidder and vast version
func (m *OWMetrics) RecordXMLParserResponseMismatch(method, bidder string, isMismatch bool) {
status := requestSuccessful
if !isMismatch {
if isMismatch {
status = requestFailed
}
m.xmlParserMismatch.With(prometheus.Labels{
methodLabel: method,
adapterLabel: bidder,
status: status,
statusLabel: status,
}).Inc()
}

Expand Down
58 changes: 58 additions & 0 deletions metrics/prometheus/prometheus_ow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,61 @@ func TestRecordFloorStatus(t *testing.T) {
})
}
}

func TestRecordXMLParserResponseMismatch(t *testing.T) {
type args struct {
method, bidder string
isMismatch bool
}
type want struct {
expCount int
status string
}
tests := []struct {
name string
args args
want want
}{
{
name: "mismatch found",
args: args{
method: "xml",
bidder: "bidder",
isMismatch: true,
},
want: want{
expCount: 1,
status: requestFailed,
},
},
{
name: "mismatch not found",
args: args{
method: "xml",
bidder: "bidder",
isMismatch: false,
},
want: want{
expCount: 1,
status: requestSuccessful,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

pm := createMetricsForTesting()
pm.RecordXMLParserResponseMismatch(tt.args.method, tt.args.bidder, tt.args.isMismatch)
assertCounterVecValue(t,
"",
"record dynamic fetch failure",
pm.xmlParserMismatch,
float64(tt.want.expCount),
prometheus.Labels{
methodLabel: tt.args.method,
adapterLabel: tt.args.bidder,
statusLabel: tt.want.status,
})
})
}
}

0 comments on commit cc2d79a

Please sign in to comment.