Skip to content

Commit

Permalink
[#4485] Allow plugins to detect and set application type
Browse files Browse the repository at this point in the history
  • Loading branch information
Xylus authored and emeroad committed Feb 15, 2019
1 parent b98f41e commit fc22830
Show file tree
Hide file tree
Showing 31 changed files with 630 additions and 418 deletions.
Expand Up @@ -174,6 +174,7 @@ public static ProfilerConfig load(String pinpointConfigFileName) throws IOExcept
private long agentInfoSendRetryInterval = DEFAULT_AGENT_INFO_SEND_RETRY_INTERVAL;

private String applicationServerType;
@Deprecated // As of 1.9.0, set application type in plugins
private List<String> applicationTypeDetectOrder = Collections.emptyList();
private List<String> pluginLoadOrder = Collections.emptyList();
private List<String> disabledPlugins = Collections.emptyList();
Expand Down Expand Up @@ -456,6 +457,10 @@ public Filter<String> getProfilableClassFilter() {
return profilableClassFilter;
}

/**
* @deprecated As of 1.9.0, set application type in plugins
*/
@Deprecated
@Override
public List<String> getApplicationTypeDetectOrder() {
return applicationTypeDetectOrder;
Expand Down
Expand Up @@ -21,7 +21,10 @@
/**
* @author Jongho Moon
*
* @deprecated As of 1.9.0, application type detection timing has been changed.
* Set the application's {@code ServiceType} directly during each plugin's setup time.
*/
@Deprecated
public interface ApplicationTypeDetector {

/**
Expand Down
@@ -0,0 +1,34 @@
/*
* Copyright 2018 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.bootstrap.plugin;

import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
import com.navercorp.pinpoint.common.trace.ServiceType;

/**
* @author HyunGil Jeong
*/
public interface ProfilerPluginGlobalContext {

ProfilerConfig getConfig();

ServiceType getConfiguredApplicationType();

ServiceType getApplicationType();

boolean registerApplicationType(ServiceType applicationType);
}
Expand Up @@ -16,6 +16,7 @@

import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
import com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcUrlParserV2;
import com.navercorp.pinpoint.common.trace.ServiceType;

/**
* Provides attributes and objects to interceptors.
Expand All @@ -35,11 +36,43 @@ public interface ProfilerPluginSetupContext {

/**
* Add a {@link ApplicationTypeDetector} to Pinpoint agent.
*
* @param detectors
*
* @param detectors application type detectors to add
*
* @deprecated As of 1.9.0, {@code ApplicationTypeDetector} has been deprecated.
* Use {@link #registerApplicationType(ServiceType)} instead.
*/
@Deprecated
void addApplicationTypeDetector(ApplicationTypeDetector... detectors);

/**
* Returns the {@link ServiceType} configured by <tt>profiler.applicationservertype</tt>
* in <i>pinpoint.config</i> file.
*
* @return the configured {@link ServiceType}
*/
ServiceType getConfiguredApplicationType();

/**
* Returns the {@link ServiceType} registered by plugins.
*
* @return the registered {@link ServiceType}
*/
ServiceType getApplicationType();

/**
* Registers the specified {@link ServiceType} to be the application type of the agent.
* Returns <tt>false</tt> if the application type has already been registered, and the
* supplied <tt>applicationType</tt> should not be registered.
* <p>
* The <tt>profiler.plugin.load.order</tt> option in <i>pinpoint.config</i> may be used
* to configure the order in which the registration happens.
*
* @param applicationType the applicationt type to be registered
* @return <tt>true</tt> if the application type is registered
*/
boolean registerApplicationType(ServiceType applicationType);

void addJdbcUrlParser(JdbcUrlParserV2 jdbcUrlParserV2);

}
Expand Up @@ -30,7 +30,11 @@
* If no match is found, the application type defaults to {@code ServiceType.STAND_ALONE}
*
* @author HyunGil Jeong
*
* @deprecated As of 1.9.0, application type detection timing has been changed to plugins' setup time.
* {@code ApplicationServerTypePluginResolver} should no longer be needed.
*/
@Deprecated
public class ApplicationServerTypePluginResolver {

private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
Expand Down
Expand Up @@ -18,7 +18,7 @@

import com.navercorp.pinpoint.bootstrap.resolver.condition.ClassResourceCondition;
import com.navercorp.pinpoint.bootstrap.resolver.condition.MainClassCondition;
import com.navercorp.pinpoint.bootstrap.resolver.condition.PropertyCondition;
import com.navercorp.pinpoint.bootstrap.resolver.condition.SystemPropertyCondition;
import com.navercorp.pinpoint.common.util.CollectionUtils;
import com.navercorp.pinpoint.common.util.StringUtils;

Expand All @@ -27,22 +27,26 @@
/**
*
* @author HyunGil Jeong
*
* @deprecated As of 1.9.0, use {@link MainClassCondition}, {@link SystemPropertyCondition},
* {@link ClassResourceCondition} directly.
*/
@Deprecated
public class ConditionProvider {

public static final ConditionProvider DEFAULT_CONDITION_PROVIDER = new ConditionProvider();

private final MainClassCondition mainClassCondition;

private final PropertyCondition systemPropertyCondition;
private final SystemPropertyCondition systemPropertyCondition;

private final ClassResourceCondition classResourceCondition;

private ConditionProvider() {
this(new MainClassCondition(), new PropertyCondition(), new ClassResourceCondition());
this(MainClassCondition.INSTANCE, SystemPropertyCondition.INSTANCE, ClassResourceCondition.INSTANCE);
}

ConditionProvider(MainClassCondition mainClassCondition, PropertyCondition systemPropertyCondition, ClassResourceCondition classResourceCondition) {
ConditionProvider(MainClassCondition mainClassCondition, SystemPropertyCondition systemPropertyCondition, ClassResourceCondition classResourceCondition) {
this.mainClassCondition = mainClassCondition;
this.systemPropertyCondition = systemPropertyCondition;
this.classResourceCondition = classResourceCondition;
Expand Down
Expand Up @@ -26,9 +26,13 @@
*/
public class ClassResourceCondition implements Condition<String> {

public static final ClassResourceCondition INSTANCE = new ClassResourceCondition();

private static final String CLASS_EXTENSION = ".class";

private final PLogger logger = PLoggerFactory.getLogger(this.getClass().getName());
private final PLogger logger = PLoggerFactory.getLogger(this.getClass().getName());

private ClassResourceCondition() {}

private String getClassNameAsResource(String className) {
String classNameAsResource = className.replace('.', '/');
Expand Down
Expand Up @@ -31,6 +31,8 @@
*/
public class MainClassCondition implements Condition<String>, ConditionValue<String> {

public static final MainClassCondition INSTANCE = new MainClassCondition();

private static final String MANIFEST_MAIN_CLASS_KEY = "Main-Class";
private static final String NOT_FOUND = null;

Expand All @@ -50,8 +52,6 @@ public MainClassCondition(SimpleProperty property) {
if (this.applicationMainClassName == NOT_FOUND) {
logger.info("Main class could not be deduced, please set 'profiler.applicationservertype' in pinpoint.config.");
logger.info("If you're running on 1.6.0_24 or prior version of Java, consider upgrading to 1.6.0_25+.");
logger.info("If you're running Tomcat or Tomcat on Spring Boot, please set 'profiler.tomcat.conditional.transform' to false");
logger.info("If you're running Jboss, please set 'profiler.tomcat.conditional.transform' to false");
}
}

Expand Down
@@ -1,74 +1,78 @@
/*
* Copyright 2015 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.bootstrap.resolver.condition;

import com.navercorp.pinpoint.bootstrap.logging.PLogger;
import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;
import com.navercorp.pinpoint.common.util.SimpleProperty;
import com.navercorp.pinpoint.common.util.StringUtils;
import com.navercorp.pinpoint.common.util.SystemProperty;

/**
* @author HyunGil Jeong
*
*/
public class PropertyCondition implements Condition<String>, ConditionValue<SimpleProperty> {

private final PLogger logger = PLoggerFactory.getLogger(this.getClass().getName());

private final SimpleProperty property;

public PropertyCondition() {
this(SystemProperty.INSTANCE);
}

public PropertyCondition(SimpleProperty property) {
this.property = property;
}

/**
* Checks if the specified value is in <tt>SimpleProperty</tt>.
*
* @param requiredKey the values to check if they exist in <tt>SimpleProperty</tt>
* @return <tt>true</tt> if the specified key is in <tt>SimpleProperty</tt>;
* <tt>false</tt> if otherwise, or if <tt>null</tt> or empty key is provided
*/
@Override
public boolean check(String requiredKey) {
if (StringUtils.isEmpty(requiredKey)) {
return false;
}
if (this.property.getProperty(requiredKey) != null) {
logger.debug("Property '{}' found in [{}]", requiredKey, this.property.getClass().getSimpleName());
return true;
} else {
logger.debug("Property '{}' not found in [{}]", requiredKey, this.property.getClass().getSimpleName());
return false;
}
}

/**
* Returns the <tt>SimpleProperty</tt>.
*
* @return the {@link SimpleProperty} instance
*/
@Override
public SimpleProperty getValue() {
return this.property;
}

}
/*
* Copyright 2015 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.bootstrap.resolver.condition;

import com.navercorp.pinpoint.bootstrap.logging.PLogger;
import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;
import com.navercorp.pinpoint.common.annotations.VisibleForTesting;
import com.navercorp.pinpoint.common.util.SimpleProperty;
import com.navercorp.pinpoint.common.util.StringUtils;
import com.navercorp.pinpoint.common.util.SystemProperty;

/**
* @author HyunGil Jeong
*
*/
public class SystemPropertyCondition implements Condition<String>, ConditionValue<SystemProperty> {

public static final SystemPropertyCondition INSTANCE = new SystemPropertyCondition();

private final PLogger logger = PLoggerFactory.getLogger(this.getClass().getName());

private final SystemProperty property;

private SystemPropertyCondition() {
this(SystemProperty.INSTANCE);
}

@VisibleForTesting
SystemPropertyCondition(SystemProperty property) {
this.property = property;
}

/**
* Checks if the specified value is in <tt>SimpleProperty</tt>.
*
* @param requiredKey the values to check if they exist in <tt>SimpleProperty</tt>
* @return <tt>true</tt> if the specified key is in <tt>SimpleProperty</tt>;
* <tt>false</tt> if otherwise, or if <tt>null</tt> or empty key is provided
*/
@Override
public boolean check(String requiredKey) {
if (StringUtils.isEmpty(requiredKey)) {
return false;
}
if (this.property.getProperty(requiredKey) != null) {
logger.debug("Property '{}' found in [{}]", requiredKey, this.property.getClass().getSimpleName());
return true;
} else {
logger.debug("Property '{}' not found in [{}]", requiredKey, this.property.getClass().getSimpleName());
return false;
}
}

/**
* Returns the <tt>SimpleProperty</tt>.
*
* @return the {@link SimpleProperty} instance
*/
@Override
public SystemProperty getValue() {
return this.property;
}

}

0 comments on commit fc22830

Please sign in to comment.