Make service instrument works
This commit is contained in:
parent
11b2170a17
commit
7bbe0693b4
|
|
@ -31,7 +31,7 @@ import java.util.ServiceLoader;
|
|||
*/
|
||||
public class ModuleManager {
|
||||
private Map<String, Module> loadedModules = new HashMap<>();
|
||||
private boolean isServiceInstrument = false;
|
||||
private boolean isServiceInstrument = true;
|
||||
|
||||
/**
|
||||
* Init the given modules
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright 2017, OpenSkywalking Organization All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Project repository: https://github.com/OpenSkywalking/skywalking
|
||||
*/
|
||||
|
||||
package org.skywalking.apm.collector.core.module.instrument;
|
||||
|
||||
/**
|
||||
* The <code>MetricCollector</code> collects the service metrics by Module/Provider/Service structure.
|
||||
*/
|
||||
public enum MetricCollector {
|
||||
INSTANCE;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -31,6 +31,9 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||
|
||||
/**
|
||||
* The <code>ServiceInstrumentation</code> create the dynamic service implementations based on the provider
|
||||
* implementation. So the new implementation will report performance metric to {@link MetricCollector}.
|
||||
*
|
||||
* @author wu-sheng
|
||||
*/
|
||||
public enum ServiceInstrumentation {
|
||||
|
|
@ -40,7 +43,7 @@ public enum ServiceInstrumentation {
|
|||
private ElementMatcher<? super MethodDescription> excludeObjectMethodsMatcher;
|
||||
|
||||
public Service buildServiceUnderMonitor(Service implementation) {
|
||||
if (TracedService.class.isInstance(implementation)) {
|
||||
if (implementation instanceof TracedService) {
|
||||
// Duplicate service instrument, ignore.
|
||||
return implementation;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright 2017, OpenSkywalking Organization All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Project repository: https://github.com/OpenSkywalking/skywalking
|
||||
*/
|
||||
|
||||
package org.skywalking.apm.collector.core.module;
|
||||
|
||||
/**
|
||||
* @author wu-sheng
|
||||
*/
|
||||
public class ModuleABusiness1Impl implements BaseModuleA.ServiceABusiness1 {
|
||||
|
||||
@Override public void print() {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright 2017, OpenSkywalking Organization All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Project repository: https://github.com/OpenSkywalking/skywalking
|
||||
*/
|
||||
|
||||
package org.skywalking.apm.collector.core.module;
|
||||
|
||||
/**
|
||||
* @author wu-sheng
|
||||
*/
|
||||
public class ModuleABusiness2Impl implements BaseModuleA.ServiceABusiness2 {
|
||||
|
||||
}
|
||||
|
|
@ -33,11 +33,11 @@ public class ModuleAProvider extends ModuleProvider {
|
|||
}
|
||||
|
||||
@Override public void prepare(Properties config) throws ServiceNotProvidedException {
|
||||
this.registerServiceImplementation(BaseModuleA.ServiceABusiness1.class, new Business1());
|
||||
this.registerServiceImplementation(BaseModuleA.ServiceABusiness1.class, new ModuleABusiness1Impl());
|
||||
}
|
||||
|
||||
@Override public void start(Properties config) throws ServiceNotProvidedException {
|
||||
this.registerServiceImplementation(BaseModuleA.ServiceABusiness2.class, new Business2());
|
||||
this.registerServiceImplementation(BaseModuleA.ServiceABusiness2.class, new ModuleABusiness2Impl());
|
||||
}
|
||||
|
||||
@Override public void notifyAfterCompleted() throws ServiceNotProvidedException {
|
||||
|
|
@ -47,14 +47,4 @@ public class ModuleAProvider extends ModuleProvider {
|
|||
@Override public String[] requiredModules() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
public class Business1 implements BaseModuleA.ServiceABusiness1 {
|
||||
|
||||
@Override public void print() {
|
||||
}
|
||||
}
|
||||
|
||||
public class Business2 implements BaseModuleA.ServiceABusiness2 {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright 2017, OpenSkywalking Organization All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Project repository: https://github.com/OpenSkywalking/skywalking
|
||||
*/
|
||||
|
||||
package org.skywalking.apm.collector.core.module;
|
||||
|
||||
/**
|
||||
* @author wu-sheng
|
||||
*/
|
||||
public class ModuleBBusiness1Impl implements BaseModuleB.ServiceBBusiness1 {
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright 2017, OpenSkywalking Organization All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Project repository: https://github.com/OpenSkywalking/skywalking
|
||||
*/
|
||||
|
||||
package org.skywalking.apm.collector.core.module;
|
||||
|
||||
/**
|
||||
* @author wu-sheng
|
||||
*/
|
||||
public class ModuleBBusiness2Impl implements BaseModuleB.ServiceBBusiness2 {
|
||||
}
|
||||
|
|
@ -33,11 +33,11 @@ public class ModuleBProvider extends ModuleProvider {
|
|||
}
|
||||
|
||||
@Override public void prepare(Properties config) throws ServiceNotProvidedException {
|
||||
this.registerServiceImplementation(BaseModuleB.ServiceBBusiness1.class, new Business1());
|
||||
this.registerServiceImplementation(BaseModuleB.ServiceBBusiness1.class, new ModuleBBusiness1Impl());
|
||||
}
|
||||
|
||||
@Override public void start(Properties config) throws ServiceNotProvidedException {
|
||||
this.registerServiceImplementation(BaseModuleB.ServiceBBusiness2.class, new Business2());
|
||||
this.registerServiceImplementation(BaseModuleB.ServiceBBusiness2.class, new ModuleBBusiness2Impl());
|
||||
}
|
||||
|
||||
@Override public void notifyAfterCompleted() throws ServiceNotProvidedException {
|
||||
|
|
@ -47,12 +47,4 @@ public class ModuleBProvider extends ModuleProvider {
|
|||
@Override public String[] requiredModules() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
public class Business1 implements BaseModuleB.ServiceBBusiness1 {
|
||||
|
||||
}
|
||||
|
||||
public class Business2 implements BaseModuleB.ServiceBBusiness2 {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,29 +30,28 @@ public class ModuleManagerTest {
|
|||
public void testInit() throws ServiceNotProvidedException, ModuleNotFoundException, ProviderNotFoundException, DuplicateProviderException {
|
||||
ApplicationConfiguration configuration = new ApplicationConfiguration();
|
||||
configuration.addModule("Test").addProviderConfiguration("TestModule-Provider", null);
|
||||
configuration.addModule("BaseA").addProviderConfiguration("P-A",null);
|
||||
configuration.addModule("BaseB").addProviderConfiguration("P-B",null);
|
||||
configuration.addModule("BaseA").addProviderConfiguration("P-A", null);
|
||||
configuration.addModule("BaseB").addProviderConfiguration("P-B", null);
|
||||
|
||||
ModuleManager manager = new ModuleManager();
|
||||
manager.init(configuration);
|
||||
|
||||
BaseModuleA.ServiceABusiness1 serviceABusiness1 = manager.find("BaseA").provider().getService(BaseModuleA.ServiceABusiness1.class);
|
||||
serviceABusiness1.print();
|
||||
Assert.assertTrue(serviceABusiness1 != null);
|
||||
}
|
||||
|
||||
//@Test
|
||||
@Test
|
||||
public void testInstrument() throws ServiceNotProvidedException, ModuleNotFoundException, ProviderNotFoundException, DuplicateProviderException {
|
||||
ApplicationConfiguration configuration = new ApplicationConfiguration();
|
||||
configuration.addModule("Test").addProviderConfiguration("TestModule-Provider", null);
|
||||
configuration.addModule("BaseA").addProviderConfiguration("P-A",null);
|
||||
configuration.addModule("BaseB").addProviderConfiguration("P-B",null);
|
||||
configuration.addModule("BaseA").addProviderConfiguration("P-A", null);
|
||||
configuration.addModule("BaseB").addProviderConfiguration("P-B", null);
|
||||
|
||||
ModuleManager manager = new ModuleManager();
|
||||
manager.setServiceInstrument(true);
|
||||
manager.init(configuration);
|
||||
|
||||
BaseModuleA.ServiceABusiness1 serviceABusiness1 = manager.find("BaseA").provider().getService(BaseModuleA.ServiceABusiness1.class);
|
||||
serviceABusiness1.print();
|
||||
BaseModuleA.ServiceABusiness1 serviceABusiness1 = manager.find("BaseA").getService(BaseModuleA.ServiceABusiness1.class);
|
||||
|
||||
Assert.assertTrue(serviceABusiness1 instanceof TracedService);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue