Skip to content

Commit

Permalink
[pinpoint-apm#9407] Add tenant id column for url stat
Browse files Browse the repository at this point in the history
  • Loading branch information
ga-ram authored and BillionaireDY committed Dec 29, 2022
1 parent ae7ed09 commit 43bb992
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.navercorp.pinpoint.metric.collector.MetricAppPropertySources;
import com.navercorp.pinpoint.metric.collector.dao.UriStatDao;
import com.navercorp.pinpoint.metric.common.model.UriStat;
import com.navercorp.pinpoint.metric.common.pinot.TenantProvider;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;
Expand All @@ -41,8 +42,11 @@ public class PinotAgentUriStatService implements AgentUriStatService {
private final int[] EMPTY_BUCKETS = new int[BUCKET_SIZE];
private final UriStatDao uriStatDao;

public PinotAgentUriStatService(UriStatDao uriStatDao) {
private final TenantProvider tenantProvider;

public PinotAgentUriStatService(UriStatDao uriStatDao, TenantProvider tenantProvider) {
this.uriStatDao = Objects.requireNonNull(uriStatDao, "uriStatDao");
this.tenantProvider = Objects.requireNonNull(tenantProvider, "tenantProvider");
}

@Override
Expand All @@ -52,13 +56,14 @@ public void save(AgentUriStatBo agentUriStatBo) {
final String applicationName = agentUriStatBo.getApplicationName();
final String agentId = agentUriStatBo.getAgentId();
final int version = agentUriStatBo.getBucketVersion();
final String tenantId = tenantProvider.getTenantId();

for (EachUriStatBo eachUriStatBo : agentUriStatBo.getEachUriStatBoList()) {
final String uri = eachUriStatBo.getUri();
final long timestamp = eachUriStatBo.getTimestamp();
final UriStatHistogram totalHistogram = eachUriStatBo.getTotalHistogram();
final UriStatHistogram failureHistogram = eachUriStatBo.getFailedHistogram();
data.add(new UriStat(timestamp, serviceName, applicationName, agentId, uri, totalHistogram.getMax(),
data.add(new UriStat(timestamp, tenantId, serviceName, applicationName, agentId, uri, totalHistogram.getMax(),
totalHistogram.getTotal(), getHistogramArray(totalHistogram), getHistogramArray(failureHistogram), version));
}
uriStatDao.insert(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

public class UriStat {
private static final long EMPTY_NUMBER = 0L;
private final String tenantId;
private final String serviceName;
private final String applicationName;
private final String agentId;
Expand All @@ -37,8 +38,9 @@ public class UriStat {
private final long timestamp;
private final int version;

public UriStat(long timestamp, String serviceName, String applicationName, String agentId, String uri, long maxLatencyMs, long totalTimeMs, int[] totalHistogram, int[] failureHistogram, int version) {
public UriStat(long timestamp, String tenantId, String serviceName, String applicationName, String agentId, String uri, long maxLatencyMs, long totalTimeMs, int[] totalHistogram, int[] failureHistogram, int version) {
this.timestamp = timestamp;
this.tenantId = tenantId;
this.serviceName = Objects.requireNonNull(serviceName, "serviceName");
this.applicationName = StringPrecondition.requireHasLength(applicationName, "applicationName");
this.agentId = StringPrecondition.requireHasLength(agentId, "agentId");
Expand All @@ -57,6 +59,7 @@ public UriStat(long timestamp, double tot0, double tot1, double tot2, double tot
double fail0, double fail1, double fail2, double fail3,
double fail4, double fail5, double fail6, double fail7, int version) {
this.timestamp = timestamp;
this.tenantId = StringUtils.EMPTY;
this.serviceName = StringUtils.EMPTY;
this.applicationName = StringUtils.EMPTY;
this.agentId = StringUtils.EMPTY;
Expand All @@ -70,6 +73,10 @@ public UriStat(long timestamp, double tot0, double tot1, double tot2, double tot
this.version = version;
}

public String getTenantId() {
return tenantId;
}

public String getServiceName() {
return serviceName;
}
Expand Down Expand Up @@ -199,5 +206,4 @@ public String toString() {
", timestamp=" + timestamp +
'}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.navercorp.pinpoint.common.util.StringUtils;
import com.navercorp.pinpoint.metric.common.model.UriStat;
import com.navercorp.pinpoint.metric.common.pinot.TenantProvider;
import com.navercorp.pinpoint.metric.web.model.UriStatSummary;
import com.navercorp.pinpoint.metric.web.service.UriStatService;
import com.navercorp.pinpoint.metric.web.util.Range;
Expand All @@ -41,9 +42,11 @@
public class UriStatController {
private final UriStatService uriStatService;
private final TimeWindowSampler DEFAULT_TIME_WINDOW_SAMPLER = new TimeWindowSlotCentricSampler(30000L, 200);
private final TenantProvider tenantProvider;

public UriStatController(UriStatService uriStatService) {
public UriStatController(UriStatService uriStatService, TenantProvider tenantProvider) {
this.uriStatService = Objects.requireNonNull(uriStatService);
this.tenantProvider = Objects.requireNonNull(tenantProvider, "tenantProvider");
}

@GetMapping("top50")
Expand All @@ -52,6 +55,7 @@ public List<UriStatSummary> getUriStatSummary(@RequestParam("applicationName") S
@RequestParam("from") long from,
@RequestParam("to") long to) {
UriStatQueryParameter.Builder builder = new UriStatQueryParameter.Builder();
builder.setTenantId(tenantProvider.getTenantId());
builder.setApplicationName(applicationName);
builder.setRange(Range.newRange(from, to));

Expand All @@ -71,6 +75,7 @@ public UriStatView getCollectedUriStat(@RequestParam("applicationName") String a
@RequestParam("to") long to) {
TimeWindow timeWindow = new TimeWindow(Range.newRange(from, to), DEFAULT_TIME_WINDOW_SAMPLER);
UriStatQueryParameter.Builder builder = new UriStatQueryParameter.Builder();
builder.setTenantId(tenantProvider.getTenantId());
builder.setApplicationName(applicationName);
builder.setUri(uri);
builder.setRange(timeWindow.getWindowRange());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,31 @@
import java.util.concurrent.TimeUnit;

public class UriStatQueryParameter extends QueryParameter {
private final String tenantId;
private final String serviceName;
private final String applicationName;
private final String agentId;
private final String uri;

protected UriStatQueryParameter(Builder builder) {
super(builder.range, builder.timePrecision, builder.limit);
this.tenantId = builder.tenantId;
this.serviceName = builder.serviceName;
this.applicationName = builder.applicationName;
this.agentId = builder.agentId;
this.uri = builder.uri;
}

public static class Builder extends QueryParameter.Builder {
private String tenantId;
private String serviceName;
private String applicationName;
private String agentId;
private String uri;

public void setTenantId(String tenantId) {
this.tenantId = tenantId;
}
public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
Expand Down
5 changes: 5 additions & 0 deletions metric-module/metric/src/main/pinot/pinot-urlStat-schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"schemaName": "uriStat",
"dimensionFieldSpecs": [
{
"name": "tenantId",
"dataType": "STRING",
"defaultNullValue": ""
},
{
"name": "serviceName",
"dataType": "STRING",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
sum(failureCount) as failureCount,
version
FROM uriStat
WHERE applicationName = #{applicationName}
WHERE tenantId = #{tenantId}
AND applicationName = #{applicationName}
AND "timestamp" BETWEEN #{range.from} AND #{range.to}
GROUP BY uri, version
ORDER BY totalCount desc
Expand All @@ -60,7 +61,8 @@
sum(failureCount) as failureCount,
version
FROM uriStat
WHERE applicationName = #{applicationName}
WHERE tenantId = #{tenantId}
AND applicationName = #{applicationName}
AND agentId = #{agentId}
AND "timestamp" BETWEEN #{range.from} AND #{range.to}
GROUP BY uri, version
Expand Down Expand Up @@ -89,7 +91,8 @@
sum(fail7) as fail7,
version
FROM uriStat
WHERE applicationName = #{applicationName}
WHERE tenantId = #{tenantId}
AND applicationName = #{applicationName}
AND uri = #{uri}
AND "timestamp" BETWEEN #{range.from} AND #{range.to}
GROUP BY "timestamp", version
Expand Down Expand Up @@ -117,7 +120,8 @@
sum(fail7) as fail7,
version
FROM uriStat
WHERE applicationName = #{applicationName}
WHERE tenantId = #{tenantId}
AND applicationName = #{applicationName}
AND agentId = #{agentId}
AND uri = #{uri}
AND "timestamp" BETWEEN #{range.from} AND #{range.to}
Expand Down

0 comments on commit 43bb992

Please sign in to comment.