Skip to content

Commit

Permalink
[#noissue] Remove duplicate mappers
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed May 7, 2024
1 parent 74fd31d commit ccafa19
Show file tree
Hide file tree
Showing 15 changed files with 159 additions and 336 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean;

import java.util.Optional;
Expand All @@ -47,7 +48,9 @@
@org.springframework.context.annotation.Configuration
@ComponentScan({
"com.navercorp.pinpoint.web.applicationmap.dao.hbase",
"com.navercorp.pinpoint.web.applicationmap.dao.mapper"
})
@Import({
MapMapperConfiguration.class
})
public class MapHbaseConfiguration {
private final Logger logger = LogManager.getLogger(MapHbaseConfiguration.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.navercorp.pinpoint.web.applicationmap.config;


import com.navercorp.pinpoint.common.hbase.RowMapper;
import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService;
import com.navercorp.pinpoint.web.applicationmap.dao.mapper.LinkFilter;
import com.navercorp.pinpoint.web.applicationmap.dao.mapper.MapStatisticsCalleeMapper;
import com.navercorp.pinpoint.web.applicationmap.dao.mapper.MapStatisticsCallerMapper;
import com.navercorp.pinpoint.web.applicationmap.dao.mapper.ResponseTimeMapper;
import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataMap;
import com.navercorp.pinpoint.web.component.ApplicationFactory;
import com.navercorp.pinpoint.web.util.TimeWindowFunction;
import com.navercorp.pinpoint.web.vo.ResponseTime;
import com.sematext.hbase.wd.RowKeyDistributorByHashPrefix;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MapMapperConfiguration {

@Bean
public RowMapper<LinkDataMap> mapStatisticsCallerMapper(ApplicationFactory applicationFactory,
@Qualifier("statisticsCallerRowKeyDistributor")
RowKeyDistributorByHashPrefix rowKeyDistributor) {
return new MapStatisticsCallerMapper(applicationFactory, rowKeyDistributor, LinkFilter::skip, TimeWindowFunction.identity());
}

@Bean
public RowMapper<LinkDataMap> mapStatisticsCallerTimeAggregatedMapper(ApplicationFactory applicationFactory,
@Qualifier("statisticsCallerRowKeyDistributor")
RowKeyDistributorByHashPrefix rowKeyDistributor) {
return new MapStatisticsCallerMapper(applicationFactory, rowKeyDistributor, LinkFilter::skip, TimeWindowFunction.ALL_IN_ONE);
}

@Bean
public RowMapper<LinkDataMap> mapStatisticsCalleeMapper(ServiceTypeRegistryService registry,
ApplicationFactory applicationFactory,
@Qualifier("statisticsCalleeRowKeyDistributor")
RowKeyDistributorByHashPrefix rowKeyDistributor) {
return new MapStatisticsCalleeMapper(registry, applicationFactory, rowKeyDistributor, LinkFilter::skip, TimeWindowFunction.identity());
}

@Bean
public RowMapper<LinkDataMap> mapStatisticsCalleeTimeAggregatedMapper(ServiceTypeRegistryService registry,
ApplicationFactory applicationFactory,
@Qualifier("statisticsCalleeRowKeyDistributor")
RowKeyDistributorByHashPrefix rowKeyDistributor) {
return new MapStatisticsCalleeMapper(registry, applicationFactory, rowKeyDistributor, LinkFilter::skip, TimeWindowFunction.ALL_IN_ONE);
}

@Bean
public RowMapper<ResponseTime> responseTimeMapper(ServiceTypeRegistryService registry,
@Qualifier("statisticsSelfRowKeyDistributor")
RowKeyDistributorByHashPrefix rowKeyDistributor) {
return new ResponseTimeMapper(registry, rowKeyDistributor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.navercorp.pinpoint.web.applicationmap.link.LinkDirection;
import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataMap;
import com.navercorp.pinpoint.web.component.ApplicationFactory;
import com.navercorp.pinpoint.web.util.TimeWindowFunction;
import com.navercorp.pinpoint.web.vo.Application;
import com.sematext.hbase.wd.RowKeyDistributorByHashPrefix;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -35,9 +36,6 @@
import org.apache.hadoop.hbase.client.Result;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.Objects;

Expand All @@ -47,29 +45,33 @@
* @author netspider
*
*/
@Component
public class MapStatisticsCalleeMapper implements RowMapper<LinkDataMap> {

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

private final LinkFilter filter;

@Autowired
private ServiceTypeRegistryService registry;
private final ServiceTypeRegistryService registry;

@Autowired
private ApplicationFactory applicationFactory;
private final ApplicationFactory applicationFactory;

@Autowired
@Qualifier("statisticsCalleeRowKeyDistributor")
private RowKeyDistributorByHashPrefix rowKeyDistributorByHashPrefix;

public MapStatisticsCalleeMapper() {
this(LinkFilter::skip);
}
private final RowKeyDistributorByHashPrefix rowKeyDistributor;

private final TimeWindowFunction timeWindowFunction;


public MapStatisticsCalleeMapper(ServiceTypeRegistryService registry,
ApplicationFactory applicationFactory,
RowKeyDistributorByHashPrefix rowKeyDistributor,
LinkFilter filter,
TimeWindowFunction timeWindowFunction) {
this.registry = Objects.requireNonNull(registry, "registry");
this.applicationFactory = Objects.requireNonNull(applicationFactory, "applicationFactory");
this.rowKeyDistributor = Objects.requireNonNull(rowKeyDistributor, "rowKeyDistributor");

public MapStatisticsCalleeMapper(LinkFilter filter) {
this.filter = Objects.requireNonNull(filter, "filter");
this.timeWindowFunction = Objects.requireNonNull(timeWindowFunction, "timeWindowFunction");
}

@Override
Expand All @@ -83,9 +85,9 @@ public LinkDataMap mapRow(Result result, int rowNum) throws Exception {

final Buffer row = new FixedBuffer(rowKey);
final Application calleeApplication = readCalleeApplication(row);
final long timestamp = TimeUtils.recoveryTimeMillis(row.readLong());
final long timestamp = timeWindowFunction.refineTimestamp(TimeUtils.recoveryTimeMillis(row.readLong()));

final LinkDataMap linkDataMap = new LinkDataMap();
final LinkDataMap linkDataMap = new LinkDataMap(timeWindowFunction);
for (Cell cell : result.rawCells()) {

final byte[] qualifier = CellUtil.cloneQualifier(cell);
Expand Down Expand Up @@ -142,6 +144,6 @@ private Application readCalleeApplication(Buffer row) {
}

private byte[] getOriginalKey(byte[] rowKey) {
return rowKeyDistributorByHashPrefix.getOriginalKey(rowKey);
return rowKeyDistributor.getOriginalKey(rowKey);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@
import com.navercorp.pinpoint.web.applicationmap.link.LinkDirection;
import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataMap;
import com.navercorp.pinpoint.web.component.ApplicationFactory;
import com.navercorp.pinpoint.web.util.TimeWindowFunction;
import com.navercorp.pinpoint.web.vo.Application;
import com.sematext.hbase.wd.RowKeyDistributorByHashPrefix;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.client.Result;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.Objects;

Expand All @@ -43,26 +41,28 @@
*
* @author netspider
*/
@Component
public class MapStatisticsCallerMapper implements RowMapper<LinkDataMap> {

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

private final LinkFilter filter;

@Autowired
private ApplicationFactory applicationFactory;
private final ApplicationFactory applicationFactory;

@Autowired
@Qualifier("statisticsCallerRowKeyDistributor")
private RowKeyDistributorByHashPrefix rowKeyDistributorByHashPrefix;
private final RowKeyDistributorByHashPrefix rowKeyDistributor;

public MapStatisticsCallerMapper() {
this(LinkFilter::skip);
}
private final TimeWindowFunction timeWindowFunction;


public MapStatisticsCallerMapper(ApplicationFactory applicationFactory,
RowKeyDistributorByHashPrefix rowKeyDistributor,
LinkFilter filter,
TimeWindowFunction timeWindowFunction) {
this.applicationFactory = Objects.requireNonNull(applicationFactory, "applicationFactory");
this.rowKeyDistributor = Objects.requireNonNull(rowKeyDistributor, "rowKeyDistributor");

public MapStatisticsCallerMapper(LinkFilter filter) {
this.filter = Objects.requireNonNull(filter, "filter");
this.timeWindowFunction = Objects.requireNonNull(timeWindowFunction, "timeWindowFunction");
}

@Override
Expand All @@ -76,7 +76,7 @@ public LinkDataMap mapRow(Result result, int rowNum) throws Exception {

final Buffer row = new FixedBuffer(rowKey);
final Application out = readCallerApplication(row);
final long timestamp = TimeUtils.recoveryTimeMillis(row.readLong());
final long timestamp = timeWindowFunction.refineTimestamp(TimeUtils.recoveryTimeMillis(row.readLong()));

// key is destApplicationName.
final LinkDataMap linkDataMap = new LinkDataMap();
Expand Down Expand Up @@ -123,6 +123,6 @@ private Application readCallerApplication(Buffer row) {
}

private byte[] getOriginalKey(byte[] rowKey) {
return rowKeyDistributorByHashPrefix.getOriginalKey(rowKey);
return rowKeyDistributor.getOriginalKey(rowKey);
}
}
Loading

0 comments on commit ccafa19

Please sign in to comment.