Skip to content

Commit

Permalink
[#noissue] Refactor MatcherGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Sep 8, 2023
1 parent 0a2a6cf commit d031433
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.navercorp.pinpoint.web.UserModule;
import com.navercorp.pinpoint.web.WebHbaseModule;
import com.navercorp.pinpoint.web.component.config.ComponentConfiguration;
import com.navercorp.pinpoint.web.hyperlink.HyperLinkConfiguration;
import com.navercorp.pinpoint.web.webhook.WebhookModule;
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
import org.springframework.context.annotation.Import;
Expand All @@ -48,6 +49,7 @@
BatchAppPropertySources.class,

ComponentConfiguration.class,
HyperLinkConfiguration.class,

MainDataSourceConfiguration.class,
MetaDataSourceConfiguration.class,
Expand Down
2 changes: 0 additions & 2 deletions batch/src/main/resources/applicationContext-batch-common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

<bean id="alarmMessageSender" class="com.navercorp.pinpoint.batch.alarm.DefaultAlarmMessageSender"/>

<bean id="hyperLinkFactory" class="com.navercorp.pinpoint.web.hyperlink.HyperLinkFactory"/>


<bean id="configProperties" class="com.navercorp.pinpoint.web.config.ConfigProperties"/>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2023 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.common.server.config;

import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertySourceFactory;

import java.util.Properties;

public class YamlPropertySourceFactory implements PropertySourceFactory {

@Override
public PropertySource<?> createPropertySource(String name, EncodedResource encodedResource) {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(encodedResource.getResource());

final String filename = encodedResource.getResource().getFilename();
final Properties properties = factory.getObject();
return new PropertiesPropertySource(filename, properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.navercorp.pinpoint.web;

import com.navercorp.pinpoint.web.component.config.ComponentConfiguration;
import com.navercorp.pinpoint.web.hyperlink.HyperLinkConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
Expand All @@ -28,7 +29,8 @@
"com.navercorp.pinpoint.web.service",
})
@Import({
ComponentConfiguration.class
ComponentConfiguration.class,
HyperLinkConfiguration.class
})
public class WebServiceConfig {
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
/*
* Copyright 2014 NAVER Corp.
* Copyright 2023 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
* 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.web.hyperlink;

/**
* @author minwoo.jung
*/
public class DefaultMatcherGroup extends MatcherGroup {

public boolean isMatchingType(LinkSource linkSource) {
return false;
public class EmptyLinkSourceMatcher implements LinkSourceMatcher {
@Override
public String getMatchingSource(LinkSource linkSource) {
return null;
}

@Override
protected String getMatchingSource(LinkSource linkSource) {
return null;
public boolean isMatchingType(LinkSource linkSource) {
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2023 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.web.hyperlink;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class HyperLinkConfiguration {
@Bean
public HyperLinkFactory HyperLinkFactory(List<MatcherGroup> matcherGroups) {
return new HyperLinkFactory(matcherGroups);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2023 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.web.hyperlink;

public interface LinkSourceMatcher {

String getMatchingSource(LinkSource linkSource);

boolean isMatchingType(LinkSource linkSource);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@
* @author emeroad
* @author minwoo.jung
*/
public abstract class MatcherGroup {
public class MatcherGroup {

final List<ServerMatcher> serverMatcherList = new ArrayList<>();
ServerMatcher defaultMatcher = new EmptyLinkMatcher();
private final List<ServerMatcher> serverMatcherList = new ArrayList<>();
private ServerMatcher defaultMatcher = new EmptyLinkMatcher();

public MatcherGroup() {
private final LinkSourceMatcher linkSourceMatcher;


public MatcherGroup(LinkSourceMatcher linkSourceMatcher) {
this.linkSourceMatcher = Objects.requireNonNull(linkSourceMatcher, "linkSourceMatcher");
}

public void setDefaultMatcher(ServerMatcher defaultMatcher) {
Expand All @@ -45,19 +49,15 @@ public void addServerMatcher(ServerMatcher serverMatcher) {

serverMatcherList.add(serverMatcher);
}

public void addMatcherGroup(MatcherGroup MatcherGroup) {
serverMatcherList.addAll(MatcherGroup.getServerMatcherList());
defaultMatcher = MatcherGroup.getDefaultMatcher();
}



public List<ServerMatcher> getServerMatcherList() {
return serverMatcherList;
}

public HyperLink makeLinkInfo(LinkSource linkSource) {
ServerMatcher serverMatcher = defaultMatcher;
String value = getMatchingSource(linkSource);
String value = linkSourceMatcher.getMatchingSource(linkSource);

Objects.requireNonNull(value, "value");

Expand All @@ -71,7 +71,17 @@ public HyperLink makeLinkInfo(LinkSource linkSource) {
return serverMatcher.getLinkInfo(value);
}

abstract protected String getMatchingSource(LinkSource linkSource);
@Override
public String toString() {
return "MatcherGroup{" +
"serverMatcherList=" + serverMatcherList +
", defaultMatcher=" + defaultMatcher +
", linkSourceMatcher=" + linkSourceMatcher +
'}';
}

public boolean isMatchingType(LinkSource linkSource) {
return linkSourceMatcher.isMatchingType(linkSource);
}

abstract public boolean isMatchingType(LinkSource linkSource);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,22 @@ private String getLink(String value) {
}

String hostName = value.substring(0, index);
return url + hostName;
return String.format(url, hostName);
}


@Override
public HyperLink getLinkInfo(String value) {
return new HyperLink(linkName, getLink(value), linkType);
}

@Override
public String toString() {
return "PostfixServerMatcher{" +
"postfix='" + postfix + '\'' +
", url='" + url + '\'' +
", linkName='" + linkName + '\'' +
", linkType=" + linkType +
'}';
}
}
2 changes: 0 additions & 2 deletions web/src/main/resources/applicationContext-web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean class="com.navercorp.pinpoint.web.hyperlink.HyperLinkFactory"/>

<bean id="commandHeaderTBaseSerializerFactory" class="com.navercorp.pinpoint.thrift.io.CommandHeaderTBaseSerializerFactory" factory-method="getDefaultInstance">
</bean>
<bean id="commandHeaderTBaseDeserializerFactory" class="com.navercorp.pinpoint.thrift.io.CommandHeaderTBaseDeserializerFactory" factory-method="getDefaultInstance">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class PostfixServerMatcherTest {

@Test
public void test() {
String url = "http://naver.com/";
String url = "http://naver.com/%s";
String postfix = ".seoul.idc";
PostfixServerMatcher matcher = new PostfixServerMatcher(postfix, url, "NAVER", LinkType.ATAG);

Expand Down

0 comments on commit d031433

Please sign in to comment.