forked from pinpoint-apm/pinpoint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pinpoint-apm#9380] Supports Line number and location in Callstack
Add Line number and location in APIMetaDataBO If Line number is null, value `0` location value is nullable
- Loading branch information
Showing
8 changed files
with
211 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...tor/src/test/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseApiMetaDataDaoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.navercorp.pinpoint.collector.dao.hbase; | ||
|
||
import com.navercorp.pinpoint.common.hbase.HbaseColumnFamily; | ||
import com.navercorp.pinpoint.common.hbase.HbaseOperations2; | ||
import com.navercorp.pinpoint.common.hbase.TableNameProvider; | ||
import com.navercorp.pinpoint.common.server.bo.ApiMetaDataBo; | ||
import com.navercorp.pinpoint.common.server.bo.MethodTypeEnum; | ||
import com.navercorp.pinpoint.common.server.hbase.DistributorConfiguration; | ||
import com.sematext.hbase.wd.RowKeyDistributorByHashPrefix; | ||
import org.apache.hadoop.hbase.Cell; | ||
import org.apache.hadoop.hbase.client.Put; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.doAnswer; | ||
import static org.mockito.Mockito.mock; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class HbaseApiMetaDataDaoTest { | ||
|
||
// from node: ApiMetaDataBo{agentId='express-node-sample-id', startTime=1669280767548, apiId=12, apiInfo='express.Function.proto.get(path, callback)', lineNumber=169, methodTypeEnum=DEFAULT, location='/Users/workspace/pinpoint/@pinpoint-naver-apm/pinpoint-agent-node/samples/express/src/routes/index.js'} | ||
@Test | ||
public void testInsert() { | ||
HbaseOperations2 mockedHbaseTemplate = mock(HbaseOperations2.class); | ||
TableNameProvider mockedProvider = mock(TableNameProvider.class); | ||
DistributorConfiguration givenConfiguration = new DistributorConfiguration(); | ||
RowKeyDistributorByHashPrefix givenRowKeyDistributorByHashPrefix = givenConfiguration.getMetadataRowKeyDistributor(); | ||
HbaseApiMetaDataDao dut = new HbaseApiMetaDataDao(mockedHbaseTemplate, mockedProvider, givenRowKeyDistributorByHashPrefix); | ||
|
||
doAnswer((invocation) -> { | ||
Put actual = invocation.getArgument(1); | ||
List<Cell> actualCells = actual.get(HbaseColumnFamily.API_METADATA_API.getName(), HbaseColumnFamily.API_METADATA_API.QUALIFIER_SIGNATURE); | ||
assertThat(actualCells).hasSize(1); | ||
return null; | ||
}).when(mockedHbaseTemplate).put(any(), any(Put.class)); | ||
|
||
ApiMetaDataBo stub = new ApiMetaDataBo.Builder("express-node-sample-id", 1669280767548L, 12, 169, MethodTypeEnum.DEFAULT, "express.Function.proto.get(path, callback)") | ||
.setLocation("/Users/workspace/pinpoint/@pinpoint-naver-apm/pinpoint-agent-node/samples/express/src/routes/index.js") | ||
.build(); | ||
dut.insert(stub); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...c/test/java/com/navercorp/pinpoint/collector/handler/grpc/GrpcApiMetaDataHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.navercorp.pinpoint.collector.handler.grpc; | ||
|
||
import com.navercorp.pinpoint.collector.service.ApiMetaDataService; | ||
import com.navercorp.pinpoint.common.server.bo.ApiMetaDataBo; | ||
import com.navercorp.pinpoint.common.server.bo.MethodTypeEnum; | ||
import com.navercorp.pinpoint.grpc.Header; | ||
import com.navercorp.pinpoint.grpc.server.ServerContext; | ||
import com.navercorp.pinpoint.grpc.trace.PApiMetaData; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.MockedStatic; | ||
import java.util.Collections; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class GrpcApiMetaDataHandlerTest { | ||
// ApiMetaDataBo{agentId='express-node-sample-id', startTime=1668495162817, apiId=11, apiInfo='express.Function.proto.get(path, callback)', lineNumber=177, methodTypeEnum=DEFAULT} | ||
// from Node agent [11, 'express.Function.proto.get(path, callback)', 24, null, '/Users/workspace/pinpoint/@pinpoint-naver-apm/pinpoint-agent-node/samples/express/src/routes/index.js'] | ||
@Test | ||
public void stubToApiMetaData() { | ||
ApiMetaDataService mockedService = mock(ApiMetaDataService.class); | ||
GrpcApiMetaDataHandler dut = new GrpcApiMetaDataHandler(mockedService); | ||
|
||
PApiMetaData actualStub = PApiMetaData.newBuilder() | ||
.setApiId(13) | ||
.setApiInfo("express.Function.proto.get(path, callback)") | ||
.setLine(177) | ||
.setType(MethodTypeEnum.DEFAULT.getCode()) | ||
.setLocation("/Users/workspace/pinpoint/@pinpoint-naver-apm/pinpoint-agent-node/samples/express/src/routes/index.js") | ||
.build(); | ||
try (MockedStatic<ServerContext> mocked = mockStatic(ServerContext.class)) { | ||
mocked.when(ServerContext::getAgentInfo).thenReturn(new Header("name", "express-node-sample-id", "agentName", "applicationName", 0, 1668495162817L, 0, Collections.emptyList())); | ||
doAnswer((invocation) -> { | ||
ApiMetaDataBo actual = invocation.getArgument(0); | ||
assertThat(actual).extracting("agentId", "startTime", "apiId", "apiInfo", "lineNumber", "methodTypeEnum", "location") | ||
.contains("express-node-sample-id", 1668495162817L, 13, "express.Function.proto.get(path, callback)", 177, MethodTypeEnum.DEFAULT, "/Users/workspace/pinpoint/@pinpoint-naver-apm/pinpoint-agent-node/samples/express/src/routes/index.js"); | ||
return null; | ||
}).when(mockedService).insert(any()); | ||
|
||
dut.handleApiMetaData(actualStub); | ||
|
||
mocked.verify(ServerContext::getAgentInfo); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
collector/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mock-maker-inline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
web/src/test/java/com/navercorp/pinpoint/web/mapper/ApiMetaDataMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.navercorp.pinpoint.web.mapper; | ||
|
||
import com.navercorp.pinpoint.common.buffer.AutomaticBuffer; | ||
import com.navercorp.pinpoint.common.buffer.Buffer; | ||
import com.navercorp.pinpoint.common.server.bo.ApiMetaDataBo; | ||
import com.navercorp.pinpoint.common.server.bo.MethodTypeEnum; | ||
import com.navercorp.pinpoint.common.server.bo.serializer.metadata.MetadataEncoder; | ||
import com.navercorp.pinpoint.common.server.hbase.DistributorConfiguration; | ||
import com.sematext.hbase.wd.RowKeyDistributorByHashPrefix; | ||
import org.apache.hadoop.hbase.Cell; | ||
import org.apache.hadoop.hbase.CellUtil; | ||
import org.apache.hadoop.hbase.HConstants; | ||
import org.apache.hadoop.hbase.KeyValue; | ||
import org.apache.hadoop.hbase.client.Result; | ||
import org.apache.hadoop.hbase.util.Bytes; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class ApiMetaDataMapperTest { | ||
// from node: ApiMetaDataBo{agentId='express-node-sample-id', startTime=1669280767548, apiId=12, apiInfo='express.Function.proto.get(path, callback)', lineNumber=169, methodTypeEnum=DEFAULT, location='/Users/workspace/pinpoint/@pinpoint-naver-apm/pinpoint-agent-node/samples/express/src/routes/index.js'} | ||
@Test | ||
public void testMapRow() throws Exception { | ||
ApiMetaDataBo expected = new ApiMetaDataBo.Builder("express-node-sample-id", 1669280767548L, 12, 169, MethodTypeEnum.DEFAULT, "express.Function.proto.get(path, callback)") | ||
.setLocation("/Users/workspace/pinpoint/@pinpoint-naver-apm/pinpoint-agent-node/samples/express/src/routes/index.js") | ||
.build(); | ||
|
||
RowKeyDistributorByHashPrefix givenRowKeyDistributorByHashPrefix = new DistributorConfiguration().getMetadataRowKeyDistributor(); | ||
final byte[] rowKey = givenRowKeyDistributorByHashPrefix.getDistributedKey(new MetadataEncoder().encodeRowKey(expected)); | ||
final Buffer buffer = new AutomaticBuffer(64); | ||
final String api = expected.getApiInfo(); | ||
buffer.putPrefixedString(api); | ||
buffer.putInt(expected.getLineNumber()); | ||
buffer.putInt(expected.getMethodTypeEnum().getCode()); | ||
|
||
String location = expected.getLocation(); | ||
if (location != null) { | ||
buffer.putPrefixedString(location); | ||
} | ||
byte[] bufferArray = buffer.getBuffer(); | ||
byte[] valueArray = Bytes.toBytes(1L); | ||
Cell cell = CellUtil.createCell(HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, bufferArray, HConstants.LATEST_TIMESTAMP, KeyValue.Type.Maximum.getCode(), valueArray); | ||
|
||
Result mockedResult = mock(Result.class); | ||
when(mockedResult.rawCells()).thenReturn(new Cell[] { cell }); | ||
when(mockedResult.getRow()).thenReturn(rowKey); | ||
|
||
ApiMetaDataMapper dut = new ApiMetaDataMapper(givenRowKeyDistributorByHashPrefix); | ||
ApiMetaDataBo actual = dut.mapRow(mockedResult, 0).get(0); | ||
|
||
assertThat(actual).extracting("agentId", "startTime", "apiId", "apiInfo", "lineNumber", "methodTypeEnum", "location") | ||
.contains(expected.getAgentId(), expected.getAgentStartTime(), expected.getId(), expected.getApiInfo(), expected.getLineNumber(), expected.getMethodTypeEnum(), expected.getLocation()); | ||
} | ||
} |