Skip to content

Commit fc4d6a9

Browse files
committed
Add metrics
1 parent bbb9e27 commit fc4d6a9

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

src/main/java/org/prebid/server/auction/externalortb/ProfilesProcessor.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public Future<BidRequest> process(AuctionContext auctionContext, BidRequest bidR
8686
.orElse(null);
8787

8888
return fetchProfiles(accountId, profilesIds, timeoutMillis(bidRequest))
89-
.map(profiles -> emitMetrics(accountId, profiles, auctionContext))
89+
.compose(profiles -> emitMetrics(accountId, profiles, auctionContext))
9090
.map(profiles -> mergeResults(
9191
applyRequestProfiles(profilesIds.request(), profiles.getStoredIdToRequest(), bidRequest),
9292
applyImpsProfiles(profilesIds.imps(), profiles.getStoredIdToImp(), bidRequest.getImp())))
@@ -109,7 +109,7 @@ private AllProfilesIds profilesIds(BidRequest bidRequest, AuctionContext auction
109109

110110
if (auctionContext.getDebugContext().isDebugEnabled() && !profilesIds.equals(initialProfilesIds)) {
111111
auctionContext.getDebugWarnings().add("Profiles exceeded the limit.");
112-
metrics.updateProfileMetric(MetricName.err); // TODO
112+
metrics.updateProfileMetric(MetricName.limit_exceeded);
113113
}
114114

115115
return profilesIds;
@@ -171,26 +171,28 @@ private Future<StoredDataResult<Profile>> fetchProfiles(String accountId,
171171
.collect(Collectors.toSet());
172172
final Timeout timeout = timeoutFactory.create(timeoutMillis);
173173

174-
return applicationSettings.getProfiles(accountId, requestProfilesIds, impProfilesIds, timeout)
175-
.compose(profiles -> profiles.getErrors().isEmpty() || !failOnUnknown
176-
? Future.succeededFuture(profiles)
177-
: Future.failedFuture(new InvalidProfileException(profiles.getErrors())));
174+
return applicationSettings.getProfiles(accountId, requestProfilesIds, impProfilesIds, timeout);
178175
}
179176

180-
private StoredDataResult<Profile> emitMetrics(String accountId,
181-
StoredDataResult<Profile> fetchResult,
182-
AuctionContext auctionContext) {
177+
private Future<StoredDataResult<Profile>> emitMetrics(String accountId,
178+
StoredDataResult<Profile> fetchResult,
179+
AuctionContext auctionContext) {
183180

184-
if (!fetchResult.getErrors().isEmpty()) {
181+
final List<String> errors = fetchResult.getErrors();
182+
if (!errors.isEmpty()) {
185183
metrics.updateProfileMetric(MetricName.missing);
186184

187185
if (auctionContext.getDebugContext().isDebugEnabled()) {
188186
metrics.updateAccountProfileMetric(accountId, MetricName.missing);
189-
auctionContext.getDebugWarnings().addAll(fetchResult.getErrors());
187+
auctionContext.getDebugWarnings().addAll(errors);
188+
}
189+
190+
if (failOnUnknown) {
191+
return Future.failedFuture(new InvalidProfileException(errors));
190192
}
191193
}
192194

193-
return fetchResult;
195+
return Future.succeededFuture(fetchResult);
194196
}
195197

196198
private BidRequest applyRequestProfiles(List<String> profilesIds,

src/main/java/org/prebid/server/metric/MetricName.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ public enum MetricName {
156156

157157
// activity
158158
disallowed_count("disallowed.count"),
159-
processed_rules_count("processedrules.count");
159+
processed_rules_count("processedrules.count"),
160+
161+
// profiles
162+
limit_exceeded;
160163

161164
private final String name;
162165

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
package org.prebid.server.metric;
22

33
import com.codahale.metrics.MetricRegistry;
4-
import org.apache.commons.lang3.StringUtils;
54

65
import java.util.Objects;
76
import java.util.function.Function;
87

98
class ProfileMetrics extends UpdatableMetrics {
109

1110
ProfileMetrics(MetricRegistry metricRegistry, CounterType counterType) {
12-
this(metricRegistry, counterType, StringUtils.EMPTY);
11+
super(Objects.requireNonNull(metricRegistry), Objects.requireNonNull(counterType), nameCreator());
1312
}
1413

1514
ProfileMetrics(MetricRegistry metricRegistry, CounterType counterType, String prefix) {
1615
super(
1716
Objects.requireNonNull(metricRegistry),
1817
Objects.requireNonNull(counterType),
19-
nameCreator(Objects.requireNonNull(prefix) + "."));
18+
nameCreator(Objects.requireNonNull(prefix)));
19+
}
20+
21+
private static Function<MetricName, String> nameCreator() {
22+
return "profiles.%s"::formatted;
2023
}
2124

2225
private static Function<MetricName, String> nameCreator(String prefix) {
23-
return metricName -> "%sprofile.%s".formatted(prefix, metricName);
26+
return metricName -> "%s.profiles.%s".formatted(prefix, metricName);
2427
}
2528
}

0 commit comments

Comments
 (0)