-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#10940] Fix mongodb mongodbClient constructor
- Loading branch information
1 parent
91b75e3
commit 93aab08
Showing
3 changed files
with
77 additions
and
11 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
75 changes: 75 additions & 0 deletions
75
.../com/navercorp/pinpoint/plugin/mongo/interceptor/MongoClientV4ConstructorInterceptor.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,75 @@ | ||
/* | ||
* Copyright 2022 NAVER Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.navercorp.pinpoint.plugin.mongo.interceptor; | ||
|
||
import com.mongodb.MongoClientSettings; | ||
import com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor; | ||
import com.navercorp.pinpoint.bootstrap.logging.PluginLogManager; | ||
import com.navercorp.pinpoint.bootstrap.logging.PluginLogger; | ||
import com.navercorp.pinpoint.common.util.ArrayArgumentUtils; | ||
import com.navercorp.pinpoint.plugin.mongo.HostListAccessor; | ||
import com.navercorp.pinpoint.plugin.mongo.MongoUtil; | ||
|
||
import java.util.List; | ||
|
||
public class MongoClientV4ConstructorInterceptor implements AroundInterceptor { | ||
private final PluginLogger logger = PluginLogManager.getLogger(this.getClass()); | ||
private final boolean isDebug = logger.isDebugEnabled(); | ||
|
||
public MongoClientV4ConstructorInterceptor() { | ||
} | ||
|
||
@Override | ||
public void before(Object target, Object[] args) { | ||
} | ||
|
||
@Override | ||
public void after(Object target, Object[] args, Object result, Throwable throwable) { | ||
if (isDebug) { | ||
logger.afterInterceptor(target, args, result, throwable); | ||
} | ||
|
||
if (throwable != null) { | ||
return; | ||
} | ||
|
||
if (Boolean.FALSE == (target instanceof HostListAccessor)) { | ||
return; | ||
} | ||
|
||
try { | ||
// over 4.2 | ||
final MongoClientSettings mongoClientSettings = ArrayArgumentUtils.getArgument(args, 0, MongoClientSettings.class); | ||
if (mongoClientSettings != null) { | ||
List<String> list = MongoUtil.getHostList(mongoClientSettings); | ||
setHostList(target, list); | ||
return; | ||
} | ||
} catch (Throwable th) { | ||
if (logger.isWarnEnabled()) { | ||
logger.warn("AFTER error. Caused:{}", th.getMessage(), th); | ||
} | ||
} | ||
} | ||
|
||
private void setHostList(Object target, List<String> hostList) { | ||
((HostListAccessor) target)._$PINPOINT$_setHostList(hostList); | ||
if (isDebug) { | ||
logger.debug("Set hostList={}", hostList); | ||
} | ||
} | ||
} |