Skip to content

Commit

Permalink
[#noissue] Use MapStruct to map query entities to models
Browse files Browse the repository at this point in the history
  • Loading branch information
intr3p1d committed Jan 2, 2025
1 parent 0bfe6d6 commit 407ea8e
Show file tree
Hide file tree
Showing 23 changed files with 910 additions and 125 deletions.
23 changes: 23 additions & 0 deletions uristat/uristat-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,34 @@
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-uristat-common</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</dependency>
</dependencies>

<properties>
<jdk.version>17</jdk.version>
<jdk.home>${env.JAVA_17_HOME}</jdk.home>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
<!-- other annotation processors -->
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import com.navercorp.pinpoint.pinot.config.PinotConfiguration;
import com.navercorp.pinpoint.uristat.web.config.UriStatChartTypeConfiguration;
import com.navercorp.pinpoint.uristat.web.config.UriStatPinotDaoConfiguration;
import com.navercorp.pinpoint.uristat.web.mapper.EntityToModelMapper;
import com.navercorp.pinpoint.uristat.web.mapper.MapperConfig;
import org.mapstruct.factory.Mappers;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
Expand All @@ -19,6 +23,7 @@
UriStatWebPropertySources.class,
UriStatChartTypeConfiguration.class,
UriStatPinotDaoConfiguration.class,
MapperConfig.class,
PinotConfiguration.class
})
@Profile("uri")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
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.UriStatSummaryEntity;
import com.navercorp.pinpoint.uristat.web.model.UriStatChartValue;
import com.navercorp.pinpoint.uristat.web.model.UriStatSummary;
import com.navercorp.pinpoint.uristat.web.util.UriStatChartQueryParameter;
Expand All @@ -13,6 +19,12 @@ 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(UriStatSummaryEntity.class);
typeAliasRegistry.registerAlias(UriStatSummaryQueryParameter.class);
typeAliasRegistry.registerAlias(UriStatChartQueryParameter.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ public class UriStatChartTypeConfiguration {
);

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


@Bean
public UriStatChartType uriStatFailureChart(@Qualifier("pinotFailureCountChartDao") UriStatChartDao chartDao) {
return new DefaultUriStatChartType("failure", HISTOGRAM_FIELD, chartDao);
Expand All @@ -52,10 +50,10 @@ public UriStatChartType uriStatLatencyChart(@Qualifier("pinotLatencyChartDao") U
return new DefaultUriStatChartType("latency", field, chartDao);
}


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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private Range checkTimeRange(long from, long to) {
return range;
}

@GetMapping("summary")
@GetMapping("/summary")
public List<UriStatSummary> getUriStatPagedSummary(
@RequestParam("applicationName") String applicationName,
@RequestParam(value = "agentId", required = false) String agentId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.navercorp.pinpoint.uristat.web.dao;

import com.navercorp.pinpoint.uristat.web.entity.ApdexChartEntity;
import com.navercorp.pinpoint.uristat.web.mapper.EntityToModelMapper;
import com.navercorp.pinpoint.uristat.web.model.UriStatChartValue;
import com.navercorp.pinpoint.uristat.web.util.UriStatChartQueryParameter;
import org.mybatis.spring.SqlSessionTemplate;
Expand All @@ -15,13 +17,21 @@ public class PinotApdexChartDao implements UriStatChartDao {
private static final String SELECT_APDEX_CHART = "selectUriApdex";

private final SqlSessionTemplate sqlPinotSessionTemplate;
private final EntityToModelMapper mapper;

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

@Override
public List<UriStatChartValue> getChartData(UriStatChartQueryParameter queryParameter) {
return sqlPinotSessionTemplate.selectList(NAMESPACE + SELECT_APDEX_CHART, queryParameter);
List<ApdexChartEntity> entities = sqlPinotSessionTemplate.selectList(NAMESPACE + SELECT_APDEX_CHART, queryParameter);
return entities.stream()
.map(mapper::toModel
).toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.navercorp.pinpoint.uristat.web.dao;

import com.navercorp.pinpoint.uristat.web.entity.FailureChartEntity;
import com.navercorp.pinpoint.uristat.web.mapper.EntityToModelMapper;
import com.navercorp.pinpoint.uristat.web.model.UriStatChartValue;
import com.navercorp.pinpoint.uristat.web.util.UriStatChartQueryParameter;
import org.mybatis.spring.SqlSessionTemplate;
Expand All @@ -15,13 +17,21 @@ public class PinotFailureCountChartDao implements UriStatChartDao {
private static final String SELECT_FAILURE_CHART = "selectFailedUriStat";

private final SqlSessionTemplate sqlPinotSessionTemplate;
private final EntityToModelMapper mapper;

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

@Override
public List<UriStatChartValue> getChartData(UriStatChartQueryParameter queryParameter) {
return sqlPinotSessionTemplate.selectList(NAMESPACE + SELECT_FAILURE_CHART, queryParameter);
List<FailureChartEntity> entities = sqlPinotSessionTemplate.selectList(NAMESPACE + SELECT_FAILURE_CHART, queryParameter);
return entities.stream()
.map(mapper::toModel
).toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.navercorp.pinpoint.uristat.web.dao;

import com.navercorp.pinpoint.uristat.web.entity.LatencyChartEntity;
import com.navercorp.pinpoint.uristat.web.mapper.EntityToModelMapper;
import com.navercorp.pinpoint.uristat.web.model.UriStatChartValue;
import com.navercorp.pinpoint.uristat.web.util.UriStatChartQueryParameter;
import org.mybatis.spring.SqlSessionTemplate;
Expand All @@ -15,14 +17,22 @@ public class PinotLatencyChartDao implements UriStatChartDao {
private static final String SELECT_LATENCY_CHART = "selectUriLatency";

private final SqlSessionTemplate sqlPinotSessionTemplate;
private final EntityToModelMapper mapper;

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

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

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

import com.navercorp.pinpoint.uristat.web.entity.TotalChartEntity;
import com.navercorp.pinpoint.uristat.web.mapper.EntityToModelMapper;
import com.navercorp.pinpoint.uristat.web.model.UriStatChartValue;
import com.navercorp.pinpoint.uristat.web.util.UriStatChartQueryParameter;
import org.mybatis.spring.SqlSessionTemplate;
Expand All @@ -15,13 +17,22 @@ public class PinotTotalCountChartDao implements UriStatChartDao {
private static final String SELECT_TOTAL_CHART = "selectTotalUriStat";

private final SqlSessionTemplate sqlPinotSessionTemplate;
private final EntityToModelMapper mapper;

public PinotTotalCountChartDao(@Qualifier("uriStatPinotSessionTemplate") SqlSessionTemplate sqlPinotSessionTemplate) {

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

@Override
public List<UriStatChartValue> getChartData(UriStatChartQueryParameter queryParameter) {
return sqlPinotSessionTemplate.selectList(NAMESPACE + SELECT_TOTAL_CHART, queryParameter);
List<TotalChartEntity> entities = sqlPinotSessionTemplate.selectList(NAMESPACE + SELECT_TOTAL_CHART, queryParameter);
return entities.stream()
.map(mapper::toModel
).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

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.model.UriStatSummary;
import com.navercorp.pinpoint.uristat.web.util.UriStatSummaryQueryParameter;
import org.apache.logging.log4j.LogManager;
Expand All @@ -34,14 +36,22 @@ public class PinotUriStatSummaryDao implements UriStatSummaryDao {
private static final String NAMESPACE = PinotUriStatSummaryDao.class.getName() + ".";
private static final String SELECT_URI_STAT_SUMMARY = "uriStatSummary";
private final SqlSessionTemplate sqlPinotSessionTemplate;
private final EntityToModelMapper mapper;

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

@Override
public List<UriStatSummary> getUriStatPagedSummary(UriStatSummaryQueryParameter queryParameter) {
return sqlPinotSessionTemplate.selectList(NAMESPACE + SELECT_URI_STAT_SUMMARY, queryParameter);
List<UriStatSummaryEntity> entities = sqlPinotSessionTemplate.selectList(NAMESPACE + SELECT_URI_STAT_SUMMARY, queryParameter);
return entities.stream()
.map(mapper::toModel
).toList();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2024 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.entity;

/**
* @author intr3p1d
*/
public class ApdexChartEntity extends ChartCommonEntity {
private Double apdexRaw;
private Double count;

public ApdexChartEntity() {
}

public Double getApdexRaw() {
return apdexRaw;
}

public void setApdexRaw(Double apdexRaw) {
this.apdexRaw = apdexRaw;
}

public Double getCount() {
return count;
}

public void setCount(Double count) {
this.count = count;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2024 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.entity;

/**
* @author intr3p1d
*/
public class ChartCommonEntity {

private long timestamp;
private String version;

public ChartCommonEntity() {
}

public long getTimestamp() {
return timestamp;
}

public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}
}
Loading

0 comments on commit 407ea8e

Please # to comment.