Skip to content

Commit

Permalink
[pinpoint-apm#9942] Add uri stat charts
Browse files Browse the repository at this point in the history
  • Loading branch information
ga-ram committed Jun 8, 2023
1 parent 6c63cd0 commit a2b2fbb
Show file tree
Hide file tree
Showing 30 changed files with 896 additions and 376 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.navercorp.pinpoint.uristat.web.chart;

import com.navercorp.pinpoint.uristat.web.dao.UriStatChartDao;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

@Component
public class UriStatApdexChart extends UriStatChartType {
private final static List<String> fieldNames = Arrays.asList("apdex");

public UriStatApdexChart(@Qualifier("pinotApdexChartDao") UriStatChartDao chartDao) {
this.type = "apdex";
this.chartDao = Objects.requireNonNull(chartDao, "chartDao");
}

@Override
public List<String> getFieldNames() {
return fieldNames;
}

@Override
public UriStatChartDao getChartDao() {
return chartDao;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.navercorp.pinpoint.uristat.web.chart;

import com.navercorp.pinpoint.uristat.web.dao.UriStatChartDao;

import java.util.List;

public abstract class UriStatChartType {
protected String type;
protected UriStatChartDao chartDao;

public abstract List<String> getFieldNames();

public abstract UriStatChartDao getChartDao();

public String getType() {
return type;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.navercorp.pinpoint.uristat.web.chart;

import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

@Component
public class UriStatChartTypeFactory {
private final List<UriStatChartType> uriStatCharts;

public UriStatChartTypeFactory(UriStatChartType... uriStatCharts) {
Objects.requireNonNull(uriStatCharts, "uriStatCharts");
this.uriStatCharts = List.of(uriStatCharts);
}

public UriStatChartType valueOf(String type) {
Objects.requireNonNull(type);
for (UriStatChartType chart : uriStatCharts) {
if (type.equals(chart.getType())) {
return chart;
}
}
throw new RuntimeException("Invalid uri stat chart type: " + type);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.navercorp.pinpoint.uristat.web.chart;

import com.navercorp.pinpoint.uristat.web.dao.UriStatChartDao;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

@Component
public class UriStatFailureChart extends UriStatChartType {
private final static List<String> fieldNames = Arrays.asList("0 ~ 100ms", "100 ~ 300ms", "300 ~ 500ms", "500 ~ 1000ms", "1000 ~ 3000ms", "3000 ~ 5000ms", "5000 ~ 8000ms", "8000ms ~");

public UriStatFailureChart(@Qualifier("pinotFailureCountChartDao") UriStatChartDao chartDao) {
this.type = "failure";
this.chartDao = Objects.requireNonNull(chartDao, "chartDao");
}

@Override
public List<String> getFieldNames() {
return fieldNames;
}

@Override
public UriStatChartDao getChartDao() {
return chartDao;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.navercorp.pinpoint.uristat.web.chart;

import com.navercorp.pinpoint.uristat.web.dao.UriStatChartDao;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

@Component
public class UriStatLatencyChart extends UriStatChartType {
private final static List<String> fieldNames = Arrays.asList("avg", "max");

public UriStatLatencyChart(@Qualifier("pinotLatencyChartDao") UriStatChartDao chartDao) {
this.type = "latency";
this.chartDao = Objects.requireNonNull(chartDao, "chartDao");
}

@Override
public List<String> getFieldNames() {
return fieldNames;
}

@Override
public UriStatChartDao getChartDao() {
return chartDao;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.navercorp.pinpoint.uristat.web.chart;

import com.navercorp.pinpoint.uristat.web.dao.UriStatChartDao;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

@Component
public class UriStatTotalChart extends UriStatChartType {
private final static List<String> fieldNames = Arrays.asList("0 ~ 100ms", "100 ~ 300ms", "300 ~ 500ms", "500 ~ 1000ms", "1000 ~ 3000ms", "3000 ~ 5000ms", "5000 ~ 8000ms", "8000ms ~");

public UriStatTotalChart(@Qualifier("pinotTotalCountChartDao") UriStatChartDao chartDao) {
this.type = "total";
this.chartDao = Objects.requireNonNull(chartDao, "chartDao");
}

@Override
public List<String> getFieldNames() {
return fieldNames;
}

@Override
public UriStatChartDao getChartDao() {
return chartDao;
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.navercorp.pinpoint.uristat.web.config;

import com.navercorp.pinpoint.metric.collector.config.MyBatisRegistryHandler;
import com.navercorp.pinpoint.uristat.web.model.UriStatHistogram;
import com.navercorp.pinpoint.uristat.web.model.UriStatChartValue;
import com.navercorp.pinpoint.uristat.web.model.UriStatSummary;
import com.navercorp.pinpoint.uristat.web.util.UriStatQueryParameter;
import com.navercorp.pinpoint.uristat.web.util.UriStatChartQueryParameter;
import com.navercorp.pinpoint.uristat.web.util.UriStatSummaryQueryParameter;
import org.apache.ibatis.type.TypeAliasRegistry;
import org.apache.ibatis.type.TypeHandlerRegistry;

public class UriRegistryHandler implements MyBatisRegistryHandler {
@Override
public void registerTypeAlias(TypeAliasRegistry typeAliasRegistry) {
typeAliasRegistry.registerAlias("UriStatHistogram", UriStatHistogram.class);
typeAliasRegistry.registerAlias("UriStatChartValue", UriStatChartValue.class);
typeAliasRegistry.registerAlias("UriStatSummary", UriStatSummary.class);
typeAliasRegistry.registerAlias("UriStatQueryParameter", UriStatQueryParameter.class);
typeAliasRegistry.registerAlias("UriStatSummaryQueryParameter", UriStatSummaryQueryParameter.class);
typeAliasRegistry.registerAlias("UriStatChartQueryParameter", UriStatChartQueryParameter.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,40 @@
package com.navercorp.pinpoint.uristat.web.controller;

import com.navercorp.pinpoint.common.util.StringUtils;
import com.navercorp.pinpoint.metric.web.util.Range;
import com.navercorp.pinpoint.metric.web.util.TimePrecision;
import com.navercorp.pinpoint.metric.web.util.TimeWindow;
import com.navercorp.pinpoint.metric.web.util.TimeWindowSampler;
import com.navercorp.pinpoint.metric.web.util.TimeWindowSlotCentricSampler;
import com.navercorp.pinpoint.metric.web.util.*;
import com.navercorp.pinpoint.pinot.tenant.TenantProvider;
import com.navercorp.pinpoint.uristat.web.model.UriStatHistogram;
import com.navercorp.pinpoint.uristat.web.chart.UriStatChartType;
import com.navercorp.pinpoint.uristat.web.chart.UriStatChartTypeFactory;
import com.navercorp.pinpoint.uristat.web.model.UriStatChartValue;
import com.navercorp.pinpoint.uristat.web.model.UriStatSummary;
import com.navercorp.pinpoint.uristat.web.service.UriStatService;
import com.navercorp.pinpoint.uristat.web.util.UriStatQueryParameter;
import com.navercorp.pinpoint.uristat.web.service.UriStatChartService;
import com.navercorp.pinpoint.uristat.web.service.UriStatSummaryService;
import com.navercorp.pinpoint.uristat.web.util.UriStatChartQueryParameter;
import com.navercorp.pinpoint.uristat.web.util.UriStatSummaryQueryParameter;
import com.navercorp.pinpoint.uristat.web.view.UriStatView;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping(value = "/uriStat")
public class UriStatController {
private final UriStatService uriStatService;
private final TimeWindowSampler DEFAULT_TIME_WINDOW_SAMPLER = new TimeWindowSlotCentricSampler(30000L, 200);
private final UriStatSummaryService uriStatService;
private final TenantProvider tenantProvider;
private final UriStatChartService uriStatChartService;
private final UriStatChartTypeFactory chartTypeFactory;
private final TimeWindowSampler DEFAULT_TIME_WINDOW_SAMPLER = new TimeWindowSlotCentricSampler(30000L, 200);

public UriStatController(UriStatService uriStatService, TenantProvider tenantProvider) {
public UriStatController(UriStatSummaryService uriStatService,
UriStatChartService uriStatChartService,
TenantProvider tenantProvider,
UriStatChartTypeFactory chartTypeFactory) {
this.uriStatService = Objects.requireNonNull(uriStatService);
this.uriStatChartService = Objects.requireNonNull(uriStatChartService);
this.chartTypeFactory = Objects.requireNonNull(chartTypeFactory);
this.tenantProvider = Objects.requireNonNull(tenantProvider, "tenantProvider");
}

Expand All @@ -59,7 +64,7 @@ public List<UriStatSummary> getUriStatPagedSummary(
@RequestParam("isDesc") boolean isDesc,
@RequestParam("count") int count
) {
UriStatQueryParameter.Builder builder = new UriStatQueryParameter.Builder()
UriStatSummaryQueryParameter.Builder builder = new UriStatSummaryQueryParameter.Builder()
.setTenantId(tenantProvider.getTenantId())
.setApplicationName(applicationName)
.setRange(Range.newRange(from, to))
Expand All @@ -83,7 +88,7 @@ public List<UriStatSummary> getUriStatSummary(
@RequestParam("from") long from,
@RequestParam("to") long to
) {
UriStatQueryParameter.Builder builder = new UriStatQueryParameter.Builder()
UriStatSummaryQueryParameter.Builder builder = new UriStatSummaryQueryParameter.Builder()
.setTenantId(tenantProvider.getTenantId())
.setApplicationName(applicationName)
.setRange(Range.newRange(from, to));
Expand All @@ -96,7 +101,8 @@ public List<UriStatSummary> getUriStatSummary(
}
}

@GetMapping("chart")
@Deprecated
@GetMapping("/chart")
public UriStatView getCollectedUriStat(
@RequestParam("applicationName") String applicationName,
@RequestParam(value = "agentId", required = false) String agentId,
Expand All @@ -106,40 +112,25 @@ public UriStatView getCollectedUriStat(
@RequestParam(value = "type", required = false) String type
) {
TimeWindow timeWindow = new TimeWindow(Range.newRange(from, to), DEFAULT_TIME_WINDOW_SAMPLER);
UriStatQueryParameter.Builder builder = new UriStatQueryParameter.Builder()
UriStatChartQueryParameter.Builder builder = new UriStatChartQueryParameter.Builder()
.setTenantId(tenantProvider.getTenantId())
.setApplicationName(applicationName)
.setUri(uri)
.setRange(timeWindow.getWindowRange())
.setTimeSize((int) timeWindow.getWindowSlotSize())
.setTimePrecision(TimePrecision.newTimePrecision(TimeUnit.MILLISECONDS, (int) timeWindow.getWindowSlotSize()));

List<UriStatHistogram> uriStats;
if (!StringUtils.isEmpty(type) && type.equalsIgnoreCase("failure")) {
uriStats = getFailedHistogramChartData(builder, agentId);
} else {
uriStats = getTotalHistogramChartData(builder, agentId);
}

return new UriStatView(uri, timeWindow, uriStats);
UriStatChartType chartType = chartTypeFactory.valueOf(type.toLowerCase());
List<UriStatChartValue> uriStats = getChartData(chartType, builder, agentId);
return new UriStatView(uri, timeWindow, uriStats, chartType);
}

private List<UriStatHistogram> getTotalHistogramChartData(UriStatQueryParameter.Builder builder, String agentId) {
private List<UriStatChartValue> getChartData(UriStatChartType chartType, UriStatChartQueryParameter.Builder builder, String agentId) {
if (StringUtils.isEmpty(agentId)) {
return uriStatService.getCollectedUriStatApplication(builder.build());
return uriStatChartService.getUriStatChartDataApplication(chartType, builder.build());
} else {
builder.setAgentId(agentId);
return uriStatService.getCollectedUriStatAgent(builder.build());
return uriStatChartService.getUriStatChartDataAgent(chartType, builder.build());
}
}

private List<UriStatHistogram> getFailedHistogramChartData(UriStatQueryParameter.Builder builder, String agentId) {
if (StringUtils.isEmpty(agentId)) {
return uriStatService.getFailedUriStatApplication(builder.build());
} else {
builder.setAgentId(agentId);
return uriStatService.getFailedUriStatAgent(builder.build());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.navercorp.pinpoint.uristat.web.dao;

import com.navercorp.pinpoint.uristat.web.model.UriStatChartValue;
import com.navercorp.pinpoint.uristat.web.util.UriStatChartQueryParameter;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;

@Repository
public class PinotApdexChartDao implements UriStatChartDao {
private static final String NAMESPACE = UriStatChartDao.class.getName() + ".";

private final SqlSessionTemplate sqlPinotSessionTemplate;

public PinotApdexChartDao(@Qualifier("uriStatPinotSessionTemplate") SqlSessionTemplate sqlPinotSessionTemplate) {
this.sqlPinotSessionTemplate = Objects.requireNonNull(sqlPinotSessionTemplate, "sqlPinotSessionTemplate");
}

@Override
public List<UriStatChartValue> getChartDataApplication(UriStatChartQueryParameter queryParameter) {
return sqlPinotSessionTemplate.selectList(NAMESPACE + "selectUriApdexApplication", queryParameter);
}

@Override
public List<UriStatChartValue> getChartDataAgent(UriStatChartQueryParameter queryParameter) {
return sqlPinotSessionTemplate.selectList(NAMESPACE + "selectUriApdexAgent", queryParameter);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.navercorp.pinpoint.uristat.web.dao;

import com.navercorp.pinpoint.uristat.web.model.UriStatChartValue;
import com.navercorp.pinpoint.uristat.web.util.UriStatChartQueryParameter;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;

@Repository
public class PinotFailureCountChartDao implements UriStatChartDao {
private static final String NAMESPACE = UriStatChartDao.class.getName() + ".";

private final SqlSessionTemplate sqlPinotSessionTemplate;

public PinotFailureCountChartDao(@Qualifier("uriStatPinotSessionTemplate") SqlSessionTemplate sqlPinotSessionTemplate) {
this.sqlPinotSessionTemplate = Objects.requireNonNull(sqlPinotSessionTemplate, "sqlPinotSessionTemplate");
}

@Override
public List<UriStatChartValue> getChartDataApplication(UriStatChartQueryParameter queryParameter) {
return sqlPinotSessionTemplate.selectList(NAMESPACE + "selectFailedUriStatApplication", queryParameter);
}

@Override
public List<UriStatChartValue> getChartDataAgent(UriStatChartQueryParameter queryParameter) {
return sqlPinotSessionTemplate.selectList(NAMESPACE + "selectFailedUriStatAgentId", queryParameter);
}
}
Loading

0 comments on commit a2b2fbb

Please sign in to comment.