Skip to content
New issue

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

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

Already on GitHub? # to your account

[#noissue] Fix mongodb plugin IT #9622

Merged
merged 1 commit into from
Jan 10, 2023
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 @@ -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