Skip to content

Commit

Permalink
Use yaml to process log and tracing advisors (apache#22992)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Dec 20, 2022
1 parent 867e76a commit 64eee82
Show file tree
Hide file tree
Showing 21 changed files with 216 additions and 332 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ public Optional<ElementMatcher<? super MethodDescription>> swapToObject(final Ya
}

private ElementMatcher<? super MethodDescription> appendParameters(final YamlPointcutConfiguration yamlPointcutConfig, final Junction<? super MethodDescription> pointcut) {
if (yamlPointcutConfig.getParams().isEmpty()) {
return pointcut.and(ElementMatchers.takesNoArguments());
}
Junction<? super MethodDescription> result = pointcut;
for (YamlPointcutParameterConfiguration each : yamlPointcutConfig.getParams()) {
result = result.and(ElementMatchers.takesArgument(each.getIndex(), ElementMatchers.named(each.getName())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ private void assertAdvisorConfiguration(final AdvisorConfiguration actual) {
assertThat(each.getAdviceClassName(), is(YamlAdviceFixture.class.getName()));
}
List<MethodAdvisorConfiguration> actualAdvisorConfig = new ArrayList<>(actual.getAdvisors());
assertThat(actualAdvisorConfig.get(0).getPointcut(), is(ElementMatchers.isConstructor().and(ElementMatchers.takesNoArguments())));
assertThat(actualAdvisorConfig.get(0).getPointcut(), is(ElementMatchers.isConstructor()));
assertThat(actualAdvisorConfig.get(1).getPointcut(), is(ElementMatchers.isConstructor().and(ElementMatchers.takesArgument(0, ElementMatchers.named("value")))));
assertThat(actualAdvisorConfig.get(2).getPointcut(), is(ElementMatchers.named("call").and(ElementMatchers.takesNoArguments())));
assertThat(actualAdvisorConfig.get(2).getPointcut(), is(ElementMatchers.named("call")));
assertThat(actualAdvisorConfig.get(3).getPointcut(), is(ElementMatchers.named("call").and(ElementMatchers.takesArgument(0, ElementMatchers.named("value")))));
assertThat(actualAdvisorConfig.get(4).getPointcut(), is(ElementMatchers.named("call")
.and(ElementMatchers.takesArgument(0, ElementMatchers.named("value1"))).and(ElementMatchers.takesArgument(1, ElementMatchers.named("value2")))));
assertThat(actualAdvisorConfig.get(5).getPointcut(), is(ElementMatchers.named("staticCall").and(ElementMatchers.takesNoArguments())));
assertThat(actualAdvisorConfig.get(5).getPointcut(), is(ElementMatchers.named("staticCall")));
assertThat(actualAdvisorConfig.get(6).getPointcut(), is(ElementMatchers.named("staticCall").and(ElementMatchers.takesArgument(0, ElementMatchers.named("value")))));
assertThat(actualAdvisorConfig.get(7).getPointcut(), is(ElementMatchers.named("staticCall")
.and(ElementMatchers.takesArgument(0, ElementMatchers.named("value1"))).and(ElementMatchers.takesArgument(1, ElementMatchers.named("value2")))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,30 @@

package org.apache.shardingsphere.agent.plugin.logging.base;

import net.bytebuddy.matcher.ElementMatchers;
import org.apache.shardingsphere.agent.config.advisor.AdvisorConfiguration;
import org.apache.shardingsphere.agent.config.advisor.MethodAdvisorConfiguration;
import org.apache.shardingsphere.agent.core.plugin.advisor.AdvisorConfigurationRegistryFactory;
import org.apache.shardingsphere.agent.plugin.logging.base.advice.MetaDataContextsFactoryAdvice;
import org.apache.shardingsphere.agent.core.plugin.yaml.loader.YamlAdvisorsConfigurationLoader;
import org.apache.shardingsphere.agent.core.plugin.yaml.swapper.YamlAdvisorsConfigurationSwapper;
import org.apache.shardingsphere.agent.spi.advisor.AdvisorDefinitionService;

import java.util.Collection;
import java.util.LinkedList;

/**
* Base logging advisor definition service.
*/
public final class BaseLoggingAdvisorDefinitionService implements AdvisorDefinitionService {

private static final String SCHEMA_METADATA_LOADER_CLASS = "org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory";
private final YamlAdvisorsConfigurationLoader loader = new YamlAdvisorsConfigurationLoader();

private static final String SCHEMA_METADATA_LOADER_METHOD_NAME = "create";

private static final String SCHEMA_METADATA_LOADER_ADVICE_CLASS = MetaDataContextsFactoryAdvice.class.getName();
private final YamlAdvisorsConfigurationSwapper swapper = new YamlAdvisorsConfigurationSwapper();

@Override
public Collection<AdvisorConfiguration> getProxyAdvisorConfigurations() {
return getAdvisorConfigurations();
return swapper.swapToObject(loader.load(getClass().getResourceAsStream("/baselogging/advisors.yaml")), getType());
}

@Override
public Collection<AdvisorConfiguration> getJDBCAdvisorConfigurations() {
return getAdvisorConfigurations();
}

private Collection<AdvisorConfiguration> getAdvisorConfigurations() {
Collection<AdvisorConfiguration> result = new LinkedList<>();
AdvisorConfiguration advisorConfig = AdvisorConfigurationRegistryFactory.getRegistry(getType()).getAdvisorConfiguration(SCHEMA_METADATA_LOADER_CLASS);
advisorConfig.getAdvisors().add(
new MethodAdvisorConfiguration(ElementMatchers.named(SCHEMA_METADATA_LOADER_METHOD_NAME).and(ElementMatchers.takesArguments(4)), SCHEMA_METADATA_LOADER_ADVICE_CLASS));
result.add(advisorConfig);
return result;
return swapper.swapToObject(loader.load(getClass().getResourceAsStream("/baselogging/advisors.yaml")), getType());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.
#

advisors:
- target: org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory
advice: org.apache.shardingsphere.agent.plugin.logging.base.advice.MetaDataContextsFactoryAdvice
pointcuts:
- name: create
type: method
params:
- index: 3
name: storageNodes
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Collection<AdvisorConfiguration> getProxyAdvisorConfigurations() {

@Override
public Collection<AdvisorConfiguration> getJDBCAdvisorConfigurations() {
// TODO add JDBC related interceptors
// TODO add JDBC advisor
return Collections.emptyList();
}

Expand Down
29 changes: 0 additions & 29 deletions agent/plugins/tracing/core/pom.xml

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 64eee82

Please sign in to comment.