Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#noissue] Remove thread local dependency of Span #10635

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.navercorp.pinpoint.common.server.bo.SpanBo;
import com.navercorp.pinpoint.common.server.bo.serializer.RowKeyEncoder;
import com.navercorp.pinpoint.common.server.hbase.config.HbaseClientConfiguration;
import com.navercorp.pinpoint.common.server.util.AcceptedTimeService;
import com.sematext.hbase.wd.AbstractRowKeyDistributor;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand Down Expand Up @@ -47,17 +46,15 @@
@Bean("applicationIndexRowKeyEncoder")
@ConditionalOnProperty(name = "collector.scatter.serverside-scan", havingValue = "v1")
public RowKeyEncoder<SpanBo> applicationIndexRowKeyEncoderV1(@Qualifier("applicationTraceIndexDistributor")
AbstractRowKeyDistributor rowKeyDistributor,
AcceptedTimeService acceptedTimeService) {
return new ApplicationIndexRowKeyEncoderV1(rowKeyDistributor, acceptedTimeService);
AbstractRowKeyDistributor rowKeyDistributor) {
return new ApplicationIndexRowKeyEncoderV1(rowKeyDistributor);

Check warning on line 50 in collector/src/main/java/com/navercorp/pinpoint/collector/CollectorHbaseModule.java

View check run for this annotation

Codecov / codecov/patch

collector/src/main/java/com/navercorp/pinpoint/collector/CollectorHbaseModule.java#L50

Added line #L50 was not covered by tests
}

@Bean("applicationIndexRowKeyEncoder")
@ConditionalOnProperty(name = "collector.scatter.serverside-scan", havingValue = "v2", matchIfMissing = true)
public RowKeyEncoder<SpanBo> applicationIndexRowKeyEncoderV2(@Qualifier("applicationTraceIndexDistributor")
AbstractRowKeyDistributor rowKeyDistributor,
AcceptedTimeService acceptedTimeService) {
return new ApplicationIndexRowKeyEncoderV2(rowKeyDistributor, acceptedTimeService);
AbstractRowKeyDistributor rowKeyDistributor) {
return new ApplicationIndexRowKeyEncoderV2(rowKeyDistributor);

Check warning on line 57 in collector/src/main/java/com/navercorp/pinpoint/collector/CollectorHbaseModule.java

View check run for this annotation

Codecov / codecov/patch

collector/src/main/java/com/navercorp/pinpoint/collector/CollectorHbaseModule.java#L57

Added line #L57 was not covered by tests
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.navercorp.pinpoint.common.hbase.async.HbasePutWriter;
import com.navercorp.pinpoint.common.server.bo.SpanBo;
import com.navercorp.pinpoint.common.server.bo.serializer.RowKeyEncoder;
import com.navercorp.pinpoint.common.server.util.AcceptedTimeService;
import com.navercorp.pinpoint.common.server.util.SpanUtils;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Put;
Expand Down Expand Up @@ -55,17 +54,13 @@
private final HbasePutWriter putWriter;
private final TableNameProvider tableNameProvider;

private final AcceptedTimeService acceptedTimeService;

private final RowKeyEncoder<SpanBo> applicationIndexRowKeyEncoder;


public HbaseApplicationTraceIndexDao(HbasePutWriter putWriter,
TableNameProvider tableNameProvider,
@Qualifier("applicationIndexRowKeyEncoder") RowKeyEncoder<SpanBo> applicationIndexRowKeyEncoder,
AcceptedTimeService acceptedTimeService) {
@Qualifier("applicationIndexRowKeyEncoder") RowKeyEncoder<SpanBo> applicationIndexRowKeyEncoder) {

Check warning on line 62 in collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseApplicationTraceIndexDao.java

View check run for this annotation

Codecov / codecov/patch

collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseApplicationTraceIndexDao.java#L62

Added line #L62 was not covered by tests
this.putWriter = Objects.requireNonNull(putWriter, "putWriter");
this.acceptedTimeService = Objects.requireNonNull(acceptedTimeService, "acceptedTimeService");
this.tableNameProvider = Objects.requireNonNull(tableNameProvider, "tableNameProvider");
this.applicationIndexRowKeyEncoder = Objects.requireNonNull(applicationIndexRowKeyEncoder, "applicationIndexRowKeyEncoder");
logger.info("ApplicationIndexRowKeyEncoder:{}", applicationIndexRowKeyEncoder);
Expand All @@ -84,7 +79,7 @@
// Assert applicationName
CollectorUtils.checkApplicationName(span.getApplicationId());

final long acceptedTime = acceptedTimeService.getAcceptedTime();
final long acceptedTime = span.getCollectorAcceptTime();

Check warning on line 82 in collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseApplicationTraceIndexDao.java

View check run for this annotation

Codecov / codecov/patch

collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseApplicationTraceIndexDao.java#L82

Added line #L82 was not covered by tests
final byte[] distributedKey = applicationIndexRowKeyEncoder.encodeRowKey(span);

final Put put = new Put(distributedKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.navercorp.pinpoint.common.server.bo.serializer.RowKeyEncoder;
import com.navercorp.pinpoint.common.server.bo.serializer.agent.ApplicationNameRowKeyEncoder;
import com.navercorp.pinpoint.common.server.bo.serializer.agent.IdRowKeyEncoder;
import com.navercorp.pinpoint.common.server.util.AcceptedTimeService;
import com.sematext.hbase.wd.AbstractRowKeyDistributor;

import java.util.Objects;
Expand All @@ -30,17 +29,15 @@

private final IdRowKeyEncoder rowKeyEncoder = new ApplicationNameRowKeyEncoder();
private final AbstractRowKeyDistributor rowKeyDistributor;
private final AcceptedTimeService acceptedTimeService;

public ApplicationIndexRowKeyEncoderV1(AbstractRowKeyDistributor rowKeyDistributor, AcceptedTimeService acceptedTimeService) {
public ApplicationIndexRowKeyEncoderV1(AbstractRowKeyDistributor rowKeyDistributor) {

Check warning on line 33 in collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/encode/ApplicationIndexRowKeyEncoderV1.java

View check run for this annotation

Codecov / codecov/patch

collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/encode/ApplicationIndexRowKeyEncoderV1.java#L33

Added line #L33 was not covered by tests
this.rowKeyDistributor = Objects.requireNonNull(rowKeyDistributor, "rowKeyDistributor");
this.acceptedTimeService = Objects.requireNonNull(acceptedTimeService, "acceptedTimeService");
}

@Override
public byte[] encodeRowKey(SpanBo span) {
// distribute key evenly
long acceptedTime = acceptedTimeService.getAcceptedTime();
long acceptedTime = span.getCollectorAcceptTime();

Check warning on line 40 in collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/encode/ApplicationIndexRowKeyEncoderV1.java

View check run for this annotation

Codecov / codecov/patch

collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/encode/ApplicationIndexRowKeyEncoderV1.java#L40

Added line #L40 was not covered by tests
final byte[] applicationTraceIndexRowKey = rowKeyEncoder.encodeRowKey(span.getApplicationId(), acceptedTime);
return rowKeyDistributor.getDistributedKey(applicationTraceIndexRowKey);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.navercorp.pinpoint.common.server.bo.serializer.agent.ApplicationNameRowKeyEncoder;
import com.navercorp.pinpoint.common.server.scatter.FuzzyRowKeyFactory;
import com.navercorp.pinpoint.common.server.scatter.OneByteFuzzyRowKeyFactory;
import com.navercorp.pinpoint.common.server.util.AcceptedTimeService;
import com.sematext.hbase.wd.AbstractRowKeyDistributor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -36,17 +35,15 @@
private final ApplicationNameRowKeyEncoder rowKeyEncoder = new ApplicationNameRowKeyEncoder();
private final FuzzyRowKeyFactory<Byte> fuzzyRowKeyFactory = new OneByteFuzzyRowKeyFactory();
private final AbstractRowKeyDistributor rowKeyDistributor;
private final AcceptedTimeService acceptedTimeService;

public ApplicationIndexRowKeyEncoderV2(AbstractRowKeyDistributor rowKeyDistributor, AcceptedTimeService acceptedTimeService) {
public ApplicationIndexRowKeyEncoderV2(AbstractRowKeyDistributor rowKeyDistributor) {
this.rowKeyDistributor = Objects.requireNonNull(rowKeyDistributor, "rowKeyDistributor");
this.acceptedTimeService = Objects.requireNonNull(acceptedTimeService, "acceptedTimeService");
}

@Override
public byte[] encodeRowKey(SpanBo span) {
// distribute key evenly
long acceptedTime = acceptedTimeService.getAcceptedTime();
long acceptedTime = span.getCollectorAcceptTime();

Check warning on line 46 in collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/encode/ApplicationIndexRowKeyEncoderV2.java

View check run for this annotation

Codecov / codecov/patch

collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/encode/ApplicationIndexRowKeyEncoderV2.java#L46

Added line #L46 was not covered by tests
byte fuzzyKey = fuzzyRowKeyFactory.getKey(span.getElapsed());
final byte[] appTraceIndexRowKey = newRowKey(span.getApplicationId(), acceptedTime, fuzzyKey);
return rowKeyDistributor.getDistributedKey(appTraceIndexRowKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
package com.navercorp.pinpoint.collector.dao.hbase.encode;

import com.navercorp.pinpoint.common.PinpointConstants;
import com.navercorp.pinpoint.common.server.util.AcceptedTimeService;
import com.navercorp.pinpoint.common.server.util.ThreadLocalAcceptedTimeService;
import com.sematext.hbase.wd.AbstractRowKeyDistributor;
import com.sematext.hbase.wd.RowKeyDistributorByHashPrefix;
import org.apache.hadoop.hbase.util.Bytes;
Expand All @@ -36,8 +34,7 @@ class ApplicationIndexRowKeyEncoderV2Test {
@BeforeEach
void beforeEach() {
AbstractRowKeyDistributor rowKeyDistributor = applicationTraceIndexDistributor();
AcceptedTimeService acceptedTimeService = new ThreadLocalAcceptedTimeService();
this.encoder = new ApplicationIndexRowKeyEncoderV2(rowKeyDistributor, acceptedTimeService);
this.encoder = new ApplicationIndexRowKeyEncoderV2(rowKeyDistributor);
}

private AbstractRowKeyDistributor applicationTraceIndexDistributor() {
Expand Down