Skip to content

Commit

Permalink
[#noissue] Fix mongodb plugin IT
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehong-kim committed Jan 10, 2023
1 parent 9804554 commit 7374de4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import static java.util.concurrent.TimeUnit.SECONDS;

public class ReactiveMongoDBITHelper {
protected static final String MONGO_REACTIVE = "MONGO_REACTIVE";
protected static final String MONGO_EXECUTE_QUERY = "MONGO_EXECUTE_QUERY";

public void testConnection(String address, final MongoDatabase database, Class<?> mongoDatabaseImplClass, String secondCollectionDefaultOption) throws Exception {
Expand Down Expand Up @@ -162,6 +163,9 @@ public void insertComlexBsonValueData34(PluginTestVerifier verifier, String addr
Method insertOneMethod = getMethod(mongoDatabaseImpl, "insertOne", Object.class);
NormalizedBson parsedBson = parseBson(document);

// execute
verifier.verifyTrace(event(MONGO_REACTIVE));

verifier.verifyTrace(event(MONGO_EXECUTE_QUERY, insertOneMethod, null, address, null
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_INFO.getName(), collectionInfo)
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), collectionOption)
Expand All @@ -181,6 +185,9 @@ public void insertData(PluginTestVerifier verifier, String address, MongoCollect
Method insertOneMethod = getMethod(mongoDatabaseImpl, "insertOne", Object.class);
NormalizedBson parsedBson = parseBson(doc);

// execute
verifier.verifyTrace(event(MONGO_REACTIVE));

verifier.verifyTrace(event(MONGO_EXECUTE_QUERY, insertOneMethod, null, address, null
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_INFO.getName(), collectionInfo)
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), collectionOption)
Expand All @@ -201,6 +208,9 @@ public void updateData(PluginTestVerifier verifier, String address, MongoCollect
Method updateOne = getMethod(mongoDatabaseImpl, "updateOne", Bson.class, Bson.class);
NormalizedBson parsedBson = parseBson(doc, doc2);

// execute
verifier.verifyTrace(event(MONGO_REACTIVE));

verifier.verifyTrace(event(MONGO_EXECUTE_QUERY, updateOne, null, address, null
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_INFO.getName(), "customers")
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), "MAJORITY")
Expand Down Expand Up @@ -243,6 +253,9 @@ public void deleteData(PluginTestVerifier verifier, String address, MongoCollect
Method deleteMany = getMethod(mongoDatabaseImpl, "deleteMany", Bson.class);
NormalizedBson parsedBson = parseBson(doc);

// execute
verifier.verifyTrace(event(MONGO_REACTIVE));

verifier.verifyTrace(event(MONGO_EXECUTE_QUERY, deleteMany, null, address, null
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_INFO.getName(), "customers")
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), "MAJORITY")
Expand All @@ -263,6 +276,9 @@ public void filterData(PluginTestVerifier verifier, String address, MongoCollect
} catch (Throwable throwable) {
}

// execute
verifier.verifyTrace(event(MONGO_REACTIVE));

verifier.verifyTrace(event(MONGO_EXECUTE_QUERY, find, null, address, null
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_INFO.getName(), "customers")
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), "secondaryPreferred")
Expand All @@ -283,6 +299,9 @@ public void filterData2(PluginTestVerifier verifier, String address, MongoCollec
} catch (Throwable throwable) {
}

// execute
verifier.verifyTrace(event(MONGO_REACTIVE));

verifier.verifyTrace(event(MONGO_EXECUTE_QUERY, find, null, address, null
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_INFO.getName(), "customers")
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), "secondaryPreferred")
Expand Down Expand Up @@ -316,7 +335,6 @@ public void onSubscribe(Subscription s) {
@Override
public void onNext(T t) {
results.add(t);
System.out.println("## Subscriber.onNext=" + t);

final int i = COUNT_UPDATER.incrementAndGet(this);
if (i >= minimumNumberOfResults) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.navercorp.pinpoint.bootstrap.plugin.jdbc.MongoDatabaseInfo;
import com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo;
import com.navercorp.pinpoint.bootstrap.util.InterceptorUtils;
import com.navercorp.pinpoint.plugin.mongo.HostListAccessor;
import com.navercorp.pinpoint.plugin.mongo.MongoConstants;
import com.navercorp.pinpoint.plugin.mongo.MongoUtil;
import com.navercorp.pinpoint.plugin.mongo.NormalizedBson;

Expand All @@ -46,13 +48,24 @@ public MongoCollectionImplReadOperationInterceptor(TraceContext traceContext, Me
public void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[] args) {
recorder.recordApi(methodDescriptor);

final DatabaseInfo databaseInfo = DatabaseInfoUtils.getDatabaseInfo(target, UnKnownDatabaseInfo.MONGO_INSTANCE);
recorder.recordServiceType(databaseInfo.getExecuteQueryType());
recorder.recordEndPoint(databaseInfo.getMultipleHost());
recorder.recordDestinationId(databaseInfo.getDatabaseId());
if (databaseInfo instanceof MongoDatabaseInfo) {
MongoUtil.recordMongoCollection(recorder, ((MongoDatabaseInfo) databaseInfo).getCollectionName(), ((MongoDatabaseInfo) databaseInfo).getReadPreference());
if (Boolean.FALSE == (target instanceof HostListAccessor)) {
return;
}

final List<String> hostList = ((HostListAccessor) target)._$PINPOINT$_getHostList();
if (hostList == null) {
return;
}

final DatabaseInfo databaseInfo = DatabaseInfoUtils.getDatabaseInfo(target, UnKnownDatabaseInfo.MONGO_INSTANCE);
final MongoDatabaseInfo mongoDatabaseInfo = new MongoDatabaseInfo(MongoConstants.MONGODB, MongoConstants.MONGO_EXECUTE_QUERY,
null, null, hostList, databaseInfo.getDatabaseId(), ((MongoDatabaseInfo) databaseInfo).getCollectionName(), ((MongoDatabaseInfo) databaseInfo).getReadPreference(), ((MongoDatabaseInfo) databaseInfo).getWriteConcern());

recorder.recordServiceType(mongoDatabaseInfo.getExecuteQueryType());
recorder.recordEndPoint(mongoDatabaseInfo.getMultipleHost());
recorder.recordDestinationId(mongoDatabaseInfo.getDatabaseId());

MongoUtil.recordMongoCollection(recorder, mongoDatabaseInfo.getCollectionName(), mongoDatabaseInfo.getReadPreference());
}

@Override
Expand Down

0 comments on commit 7374de4

Please # to comment.