Skip to content

Commit

Permalink
[#noissue] Polishing MongoPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Aug 5, 2022
1 parent 93ee21f commit 796bd8d
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 361 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.bson.BsonSymbol;
import org.bson.BsonTimestamp;
import org.bson.BsonUndefined;
import org.bson.BsonValue;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.bson.types.Decimal128;
Expand Down Expand Up @@ -134,15 +133,11 @@ public NormalizedBson parseBson(Object... documents) {

private Document createComplexDocument() {
//insert Data
BsonValue a = new BsonString("stest");
BsonValue b = new BsonDouble(111);
BsonValue c = new BsonBoolean(true);

Document document = new Document()
.append("int32", new BsonInt32(12))
.append("int64", new BsonInt64(77L))
.append("bo\"olean", new BsonBoolean(true))
.append("date", new BsonDateTime(new Date().getTime()))
.append("boolean", BsonBoolean.TRUE)
.append("date", new BsonDateTime(System.currentTimeMillis()))
.append("double", new BsonDouble(12.3))
.append("string", new BsonString("pinpoint"))
.append("objectId", new BsonObjectId(new ObjectId()))
Expand All @@ -154,7 +149,9 @@ private Document createComplexDocument() {
.append("undefined", new BsonUndefined())
.append("binary1", new BsonBinary(new byte[]{(byte) 0xe0, 0x4f, (byte) 0xd0, 0x20}))
.append("oldBinary", new BsonBinary(BsonBinarySubType.OLD_BINARY, new byte[]{1, 1, 1, 1, 1}))
.append("arrayInt", new BsonArray(Arrays.asList(a, b, c, new BsonInt32(7))))
.append("arrayInt", new BsonArray(Arrays.asList(
new BsonString("stest"), new BsonDouble(111), BsonBoolean.TRUE, new BsonInt32(7)))
)
.append("document", new BsonDocument("a", new BsonInt32(77)))
.append("dbPointer", new BsonDbPointer("db.coll", new ObjectId()))
.append("null", new BsonNull());
Expand Down Expand Up @@ -225,7 +222,7 @@ public void readData(PluginTestVerifier verifier, String address, MongoCollectio
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_INFO.getName(), "customers")
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), "secondaryPreferred")));

assertResultSize("Unexpected read data",2, cursor);
assertResultSize("Unexpected read data", 2, cursor);
}

private void assertResultSize(String message, int expected, MongoCursor<Document> cursor) {
Expand Down Expand Up @@ -255,7 +252,7 @@ public void deleteData(PluginTestVerifier verifier, String address, MongoCollect
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), "MAJORITY")
, new ExpectedAnnotation(MongoConstants.MONGO_JSON_DATA.getName(), new StringStringValue(parsedBson.getNormalizedBson(), parsedBson.getParameter()))));

Assert.assertEquals("unexcepted delete count",1, deleteResult.getDeletedCount());
Assert.assertEquals("unexcepted delete count", 1, deleteResult.getDeletedCount());
}

public void filterData(PluginTestVerifier verifier, String address, MongoCollection<Document> collection, Class<?> mongoDatabaseImpl) {
Expand All @@ -270,7 +267,7 @@ public void filterData(PluginTestVerifier verifier, String address, MongoCollect
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), "secondaryPreferred")
, new ExpectedAnnotation(MongoConstants.MONGO_JSON_DATA.getName(), new StringStringValue(parsedBson.getNormalizedBson(), parsedBson.getParameter()))));

assertResultSize("Unexpected filter data",1, cursor);
assertResultSize("Unexpected filter data", 1, cursor);
}

public void filterData2(PluginTestVerifier verifier, String address, MongoCollection<Document> collection, Class<?> mongoDatabaseImpl) {
Expand All @@ -285,6 +282,6 @@ public void filterData2(PluginTestVerifier verifier, String address, MongoCollec
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), "secondaryPreferred")
, new ExpectedAnnotation(MongoConstants.MONGO_JSON_DATA.getName(), new StringStringValue(parsedBson.getNormalizedBson(), parsedBson.getParameter()))));

assertResultSize("Unexpected filter data2",1, cursor);
assertResultSize("Unexpected filter data2", 1, cursor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.bson.BsonSymbol;
import org.bson.BsonTimestamp;
import org.bson.BsonUndefined;
import org.bson.BsonValue;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.bson.types.Decimal128;
Expand Down Expand Up @@ -101,15 +100,11 @@ public NormalizedBson parseBson(Object... documents) {

private Document createComplexDocument() {
//insert Data
BsonValue a = new BsonString("stest");
BsonValue b = new BsonDouble(111);
BsonValue c = new BsonBoolean(true);

Document document = new Document()
.append("int32", new BsonInt32(12))
.append("int64", new BsonInt64(77L))
.append("bo\"olean", new BsonBoolean(true))
.append("date", new BsonDateTime(new Date().getTime()))
.append("boolean", BsonBoolean.TRUE)
.append("date", new BsonDateTime(System.currentTimeMillis()))
.append("double", new BsonDouble(12.3))
.append("string", new BsonString("pinpoint"))
.append("objectId", new BsonObjectId(new ObjectId()))
Expand All @@ -121,7 +116,9 @@ private Document createComplexDocument() {
.append("undefined", new BsonUndefined())
.append("binary1", new BsonBinary(new byte[]{(byte) 0xe0, 0x4f, (byte) 0xd0, 0x20}))
.append("oldBinary", new BsonBinary(BsonBinarySubType.OLD_BINARY, new byte[]{1, 1, 1, 1, 1}))
.append("arrayInt", new BsonArray(Arrays.asList(a, b, c, new BsonInt32(7))))
.append("arrayInt", new BsonArray(Arrays.asList(
new BsonString("stest"), new BsonDouble(111), BsonBoolean.TRUE, new BsonInt32(7)))
)
.append("document", new BsonDocument("a", new BsonInt32(77)))
.append("dbPointer", new BsonDbPointer("db.coll", new ObjectId()))
.append("null", new BsonNull());
Expand Down Expand Up @@ -192,7 +189,7 @@ public void readData(PluginTestVerifier verifier, String address, MongoCollectio
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_INFO.getName(), "customers")
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), "secondaryPreferred")));

assertResultSize("Unexpected read data",2, cursor);
assertResultSize("Unexpected read data", 2, cursor);
}

private void assertResultSize(String message, int expected, MongoCursor<Document> cursor) {
Expand Down Expand Up @@ -220,7 +217,7 @@ public void deleteData(PluginTestVerifier verifier, String address, MongoCollect
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), "MAJORITY")
, new ExpectedAnnotation(MongoConstants.MONGO_JSON_DATA.getName(), new StringStringValue(parsedBson.getNormalizedBson(), parsedBson.getParameter()))));

Assert.assertEquals("unexcepted delete count",1, deleteResult.getDeletedCount());
Assert.assertEquals("unexcepted delete count", 1, deleteResult.getDeletedCount());
}

public void filterData(PluginTestVerifier verifier, String address, MongoCollection<Document> collection, Class<?> mongoDatabaseImpl) {
Expand All @@ -234,7 +231,7 @@ public void filterData(PluginTestVerifier verifier, String address, MongoCollect
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), "secondaryPreferred")
, new ExpectedAnnotation(MongoConstants.MONGO_JSON_DATA.getName(), new StringStringValue(parsedBson.getNormalizedBson(), parsedBson.getParameter()))));

assertResultSize("Unexpected filter data",1, cursor);
assertResultSize("Unexpected filter data", 1, cursor);
}

public void filterData2(PluginTestVerifier verifier, String address, MongoCollection<Document> collection, Class<?> mongoDatabaseImpl) {
Expand All @@ -248,6 +245,6 @@ public void filterData2(PluginTestVerifier verifier, String address, MongoCollec
, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), "secondaryPreferred")
, new ExpectedAnnotation(MongoConstants.MONGO_JSON_DATA.getName(), new StringStringValue(parsedBson.getNormalizedBson(), parsedBson.getParameter()))));

assertResultSize("Unexpected filter data2",1, cursor);
assertResultSize("Unexpected filter data2", 1, cursor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* @author Roy Kimd
*/
public class MongoConfig{
public class MongoConfig {

private final boolean enable;
private final boolean collectJson;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import java.util.List;

import static com.navercorp.pinpoint.common.trace.AnnotationKeyProperty.VIEW_IN_RECORD_SET;
import static com.navercorp.pinpoint.common.trace.ServiceTypeProperty.*;
import static com.navercorp.pinpoint.common.trace.ServiceTypeProperty.INCLUDE_DESTINATION_ID;
import static com.navercorp.pinpoint.common.trace.ServiceTypeProperty.RECORD_STATISTICS;
import static com.navercorp.pinpoint.common.trace.ServiceTypeProperty.TERMINAL;

/**
* @author Roy Kim
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static NormalizedBson parseBson(Object[] args, boolean traceBsonBindValue

String documentString = writeContext.parse(arg);

if(!documentString.equals(WriteContext.UNTRACED)) {
if (!documentString.equals(WriteContext.UNTRACED)) {
parsedJson.add(documentString);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@
package com.navercorp.pinpoint.plugin.mongo.interceptor;

import com.mongodb.MongoClientSettings;
import com.mongodb.ServerAddress;
import com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor;
import com.navercorp.pinpoint.bootstrap.logging.PLogger;
import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;
import com.navercorp.pinpoint.common.plugin.util.HostAndPort;
import com.navercorp.pinpoint.common.util.ArrayArgumentUtils;
import com.navercorp.pinpoint.plugin.mongo.HostListAccessor;
import com.navercorp.pinpoint.plugin.mongo.MongoUtil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MongoClientImplConstructorInterceptor implements AroundInterceptor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@
package com.navercorp.pinpoint.plugin.mongo.interceptor;

import com.mongodb.MongoClientSettings;
import com.mongodb.ServerAddress;
import com.navercorp.pinpoint.bootstrap.context.MethodDescriptor;
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
import com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor;
import com.navercorp.pinpoint.bootstrap.logging.PLogger;
import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;
import com.navercorp.pinpoint.common.plugin.util.HostAndPort;
import com.navercorp.pinpoint.common.util.ArrayArgumentUtils;
import com.navercorp.pinpoint.common.util.CollectionUtils;
import com.navercorp.pinpoint.plugin.mongo.HostListAccessor;
import com.navercorp.pinpoint.plugin.mongo.MongoUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

Expand Down
Loading

0 comments on commit 796bd8d

Please sign in to comment.