Skip to content

Commit

Permalink
[#11944] Include chart in /uriStat/summary response
Browse files Browse the repository at this point in the history
  • Loading branch information
intr3p1d committed Jan 17, 2025
1 parent 3f8242c commit 3dc75df
Show file tree
Hide file tree
Showing 33 changed files with 999 additions and 451 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.navercorp.pinpoint.uristat.web.chart;

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

import java.util.List;
import java.util.Objects;
Expand All @@ -28,11 +29,18 @@ public class DefaultUriStatChartType implements UriStatChartType {

private final List<String> fieldNames;
private final UriStatChartDao chartDao;
private final UriStatSummaryDao summaryDao;

public DefaultUriStatChartType(String type, List<String> fieldNames, UriStatChartDao chartDao) {
public DefaultUriStatChartType(
String type,
List<String> fieldNames,
UriStatChartDao chartDao,
UriStatSummaryDao summaryDao
) {
this.type = Objects.requireNonNull(type, "type");
this.fieldNames = Objects.requireNonNull(fieldNames, "fieldNames");
this.chartDao = Objects.requireNonNull(chartDao, "chartDao");
this.summaryDao = Objects.requireNonNull(summaryDao, "summaryDao");
}

@Override
Expand All @@ -50,12 +58,18 @@ public UriStatChartDao getChartDao() {
return chartDao;
}

@Override
public UriStatSummaryDao getSummaryDao() {
return summaryDao;
}

@Override
public String toString() {
return "UriStatChartType{" +
"type='" + type + '\'' +
", fieldNames=" + fieldNames +
", chartDao=" + chartDao.getClass().getSimpleName() +
", summaryDao=" + summaryDao.getClass().getSimpleName() +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.navercorp.pinpoint.uristat.web.chart;

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

import java.util.List;

Expand All @@ -10,5 +11,7 @@ public interface UriStatChartType {

UriStatChartDao getChartDao();

UriStatSummaryDao getSummaryDao();

String getType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand All @@ -24,7 +25,7 @@ public UriStatChartType valueOf(String type) {

final UriStatChartType uriStatChartType = uriStatCharts.get(type);
if (uriStatChartType == null) {
throw new RuntimeException("Invalid uri stat chart type: " + type);
throw new NoSuchElementException("Invalid uri stat chart type: " + type);
}
return uriStatChartType;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.navercorp.pinpoint.uristat.web.config;

import com.navercorp.pinpoint.mybatis.MyBatisRegistryHandler;
import com.navercorp.pinpoint.uristat.web.entity.ApdexChartEntity;
import com.navercorp.pinpoint.uristat.web.entity.ChartCommonEntity;
import com.navercorp.pinpoint.uristat.web.entity.FailureChartEntity;
import com.navercorp.pinpoint.uristat.web.entity.LatencyChartEntity;
import com.navercorp.pinpoint.uristat.web.entity.TotalChartEntity;
import com.navercorp.pinpoint.uristat.web.entity.UriStatChartEntity;
import com.navercorp.pinpoint.uristat.web.entity.UriStatSummaryEntity;
import com.navercorp.pinpoint.uristat.web.model.UriStatChartValue;
import com.navercorp.pinpoint.uristat.web.model.UriStatSummary;
Expand All @@ -19,11 +15,7 @@ public class UriRegistryHandler implements MyBatisRegistryHandler {
public void registerTypeAlias(TypeAliasRegistry typeAliasRegistry) {
typeAliasRegistry.registerAlias(UriStatChartValue.class);
typeAliasRegistry.registerAlias(UriStatSummary.class);
typeAliasRegistry.registerAlias(ApdexChartEntity.class);
typeAliasRegistry.registerAlias(ChartCommonEntity.class);
typeAliasRegistry.registerAlias(FailureChartEntity.class);
typeAliasRegistry.registerAlias(LatencyChartEntity.class);
typeAliasRegistry.registerAlias(TotalChartEntity.class);
typeAliasRegistry.registerAlias(UriStatChartEntity.class);
typeAliasRegistry.registerAlias(UriStatSummaryEntity.class);
typeAliasRegistry.registerAlias(UriStatSummaryQueryParameter.class);
typeAliasRegistry.registerAlias(UriStatChartQueryParameter.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.navercorp.pinpoint.uristat.web.chart.UriStatChartType;
import com.navercorp.pinpoint.uristat.web.chart.UriStatChartTypeFactory;
import com.navercorp.pinpoint.uristat.web.dao.UriStatChartDao;
import com.navercorp.pinpoint.uristat.web.dao.UriStatSummaryDao;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -35,25 +36,37 @@ public class UriStatChartTypeConfiguration {
);

@Bean
public UriStatChartType uriStatTotalChart(@Qualifier("pinotTotalCountChartDao") UriStatChartDao chartDao) {
return new DefaultUriStatChartType("total", HISTOGRAM_FIELD, chartDao);
public UriStatChartType uriStatTotalChart(
@Qualifier("pinotTotalCountChartDao") UriStatChartDao chartDao,
@Qualifier("pinotTotalSummaryDao") UriStatSummaryDao summaryDao
) {
return new DefaultUriStatChartType("total", HISTOGRAM_FIELD, chartDao, summaryDao);
}

@Bean
public UriStatChartType uriStatFailureChart(@Qualifier("pinotFailureCountChartDao") UriStatChartDao chartDao) {
return new DefaultUriStatChartType("failure", HISTOGRAM_FIELD, chartDao);
public UriStatChartType uriStatFailureChart(
@Qualifier("pinotFailureCountChartDao") UriStatChartDao chartDao,
@Qualifier("pinotFailureSummaryDao") UriStatSummaryDao summaryDao
) {
return new DefaultUriStatChartType("failure", HISTOGRAM_FIELD, chartDao, summaryDao);
}

@Bean
public UriStatChartType uriStatLatencyChart(@Qualifier("pinotLatencyChartDao") UriStatChartDao chartDao) {
public UriStatChartType uriStatLatencyChart(
@Qualifier("pinotLatencyChartDao") UriStatChartDao chartDao,
@Qualifier("pinotLatencySummaryDao") UriStatSummaryDao summaryDao
) {
List<String> field = List.of("avg", "max");
return new DefaultUriStatChartType("latency", field, chartDao);
return new DefaultUriStatChartType("latency", field, chartDao, summaryDao);
}

@Bean
public UriStatChartType uriStatApdexChart(@Qualifier("pinotApdexChartDao") UriStatChartDao chartDao) {
public UriStatChartType uriStatApdexChart(
@Qualifier("pinotApdexChartDao") UriStatChartDao chartDao,
@Qualifier("pinotApdexSummaryDao") UriStatSummaryDao summaryDao
) {
List<String> field = List.of("apdex");
return new DefaultUriStatChartType("apdex", field, chartDao);
return new DefaultUriStatChartType("apdex", field, chartDao, summaryDao);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
import com.navercorp.pinpoint.pinot.tenant.TenantProvider;
import com.navercorp.pinpoint.uristat.web.chart.UriStatChartType;
import com.navercorp.pinpoint.uristat.web.chart.UriStatChartTypeFactory;
import com.navercorp.pinpoint.uristat.web.mapper.ModelToViewMapper;
import com.navercorp.pinpoint.uristat.web.model.UriStatChartValue;
import com.navercorp.pinpoint.uristat.web.model.UriStatSummary;
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.UriStatSummaryView;
import com.navercorp.pinpoint.uristat.web.view.UriStatView;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -39,6 +41,7 @@
import org.springframework.web.bind.annotation.RestController;

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

Expand All @@ -50,18 +53,24 @@ public class UriStatController {
private final UriStatChartService uriStatChartService;
private final UriStatChartTypeFactory chartTypeFactory;
private static final TimeWindowSampler DEFAULT_TIME_WINDOW_SAMPLER = new TimeWindowSlotCentricSampler(30000L, 200);
private static final TimeWindowSampler ROUGH_TIME_WINDOW_SAMPLER = new TimeWindowSlotCentricSampler(30000L, 10);
private final RangeValidator rangeValidator;
private final ModelToViewMapper mapper;

public UriStatController(UriStatSummaryService uriStatService,
UriStatChartService uriStatChartService,
TenantProvider tenantProvider,
UriStatChartTypeFactory chartTypeFactory,
@Qualifier("rangeValidator30d") RangeValidator rangeValidator) {
public UriStatController(
UriStatSummaryService uriStatService,
UriStatChartService uriStatChartService,
TenantProvider tenantProvider,
UriStatChartTypeFactory chartTypeFactory,
@Qualifier("rangeValidator30d") RangeValidator rangeValidator,
ModelToViewMapper mapper
) {
this.uriStatService = Objects.requireNonNull(uriStatService);
this.uriStatChartService = Objects.requireNonNull(uriStatChartService);
this.chartTypeFactory = Objects.requireNonNull(chartTypeFactory);
this.tenantProvider = Objects.requireNonNull(tenantProvider, "tenantProvider");
this.rangeValidator = Objects.requireNonNull(rangeValidator, "rangeValidator");
this.mapper = Objects.requireNonNull(mapper, "mapper");
}

private Range checkTimeRange(long from, long to) {
Expand All @@ -71,27 +80,44 @@ private Range checkTimeRange(long from, long to) {
}

@GetMapping("/summary")
public List<UriStatSummary> getUriStatPagedSummary(
public List<UriStatSummaryView> getUriStatPagedSummary(
@RequestParam("applicationName") String applicationName,
@RequestParam(value = "agentId", required = false) String agentId,
@RequestParam("from") long from,
@RequestParam("to") long to,
@RequestParam("orderby") String column,
@RequestParam("isDesc") boolean isDesc,
@RequestParam("count") int count
@RequestParam("count") int count,
@RequestParam(value = "type", required = false) String type
) {
Range range = checkTimeRange(from, to);
TimeWindow timeWindow = new TimeWindow(range, ROUGH_TIME_WINDOW_SAMPLER);

UriStatSummaryQueryParameter query = new UriStatSummaryQueryParameter.Builder()
.setTenantId(tenantProvider.getTenantId())
.setApplicationName(applicationName)
.setAgentId(agentId)
.setRange(range)
.setTimeSize((int) timeWindow.getWindowSlotSize())
.setTimePrecision(TimePrecision.newTimePrecision(TimeUnit.MILLISECONDS, (int) timeWindow.getWindowSlotSize()))
.setOrderby(column)
.setDesc(isDesc)
.setLimit(count)
.build();

return uriStatService.getUriStatPagedSummary(query);
if (type == null) {
List<UriStatSummary> summaries = uriStatService.getUriStatPagedSummary(query);
return summaries.stream()
.map(mapper::toSummaryView
).toList();
} else {
UriStatChartType chartType = chartTypeFactory.valueOf(type.toLowerCase());
List<UriStatSummary> summaries = uriStatService.getUriStatMiniChart(chartType, query);
return summaries.stream()
.map((UriStatSummary e)
-> mapper.toSummaryView(e, timeWindow, chartType)
).toList();
}
}

@GetMapping("/chart")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.navercorp.pinpoint.uristat.web.dao;

import com.navercorp.pinpoint.uristat.web.entity.ApdexChartEntity;
import com.navercorp.pinpoint.uristat.web.entity.UriStatChartEntity;
import com.navercorp.pinpoint.uristat.web.mapper.EntityToModelMapper;
import com.navercorp.pinpoint.uristat.web.model.UriStatChartValue;
import com.navercorp.pinpoint.uristat.web.util.UriStatChartQueryParameter;
Expand Down Expand Up @@ -29,9 +29,9 @@ public PinotApdexChartDao(

@Override
public List<UriStatChartValue> getChartData(UriStatChartQueryParameter queryParameter) {
List<ApdexChartEntity> entities = sqlPinotSessionTemplate.selectList(NAMESPACE + SELECT_APDEX_CHART, queryParameter);
List<UriStatChartEntity> entities = sqlPinotSessionTemplate.selectList(NAMESPACE + SELECT_APDEX_CHART, queryParameter);
return entities.stream()
.map(mapper::toModel
.map(mapper::toApdexChart
).toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2025 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.navercorp.pinpoint.uristat.web.dao;

import com.navercorp.pinpoint.uristat.web.entity.UriStatSummaryEntity;
import com.navercorp.pinpoint.uristat.web.mapper.EntityToModelMapper;
import com.navercorp.pinpoint.uristat.web.mapper.MapperUtils;
import com.navercorp.pinpoint.uristat.web.model.UriStatSummary;
import com.navercorp.pinpoint.uristat.web.util.UriStatSummaryQueryParameter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* @author intr3p1d
*/
@Repository
public class PinotApdexSummaryDao implements UriStatSummaryDao {

private final Logger logger = LogManager.getLogger(this.getClass());

private static final String NAMESPACE = PinotUriStatSummaryDao.class.getName() + ".";
private static final String URI_STAT_SUMMARY_APDEX = "uriStatSummaryApdex";
private final SqlSessionTemplate sqlPinotSessionTemplate;
private final EntityToModelMapper mapper;

public PinotApdexSummaryDao(
@Qualifier("uriStatPinotSessionTemplate") SqlSessionTemplate sqlPinotSessionTemplate,
EntityToModelMapper mapper
) {
this.sqlPinotSessionTemplate = sqlPinotSessionTemplate;
this.mapper = mapper;
}

@Override
public List<UriStatSummary> getUriStatPagedSummary(UriStatSummaryQueryParameter uriStatQueryParameter) {
List<UriStatSummaryEntity> entities = sqlPinotSessionTemplate.selectList(
NAMESPACE + URI_STAT_SUMMARY_APDEX, uriStatQueryParameter
);
List<List<UriStatSummaryEntity>> listOfEntities = MapperUtils.groupByUriAndVersion(entities, uriStatQueryParameter.getLimit());
return listOfEntities.stream()
.map(mapper::toApdexSummary
).toList();
}

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

import com.navercorp.pinpoint.uristat.web.entity.FailureChartEntity;
import com.navercorp.pinpoint.uristat.web.entity.UriStatChartEntity;
import com.navercorp.pinpoint.uristat.web.mapper.EntityToModelMapper;
import com.navercorp.pinpoint.uristat.web.model.UriStatChartValue;
import com.navercorp.pinpoint.uristat.web.util.UriStatChartQueryParameter;
Expand Down Expand Up @@ -29,9 +29,9 @@ public PinotFailureCountChartDao(

@Override
public List<UriStatChartValue> getChartData(UriStatChartQueryParameter queryParameter) {
List<FailureChartEntity> entities = sqlPinotSessionTemplate.selectList(NAMESPACE + SELECT_FAILURE_CHART, queryParameter);
List<UriStatChartEntity> entities = sqlPinotSessionTemplate.selectList(NAMESPACE + SELECT_FAILURE_CHART, queryParameter);
return entities.stream()
.map(mapper::toModel
.map(mapper::toFailureChart
).toList();
}
}
Loading

0 comments on commit 3dc75df

Please sign in to comment.