Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apollo assembly optimization #5035

Merged
merged 70 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
72f014f
table prefix
vdiskg Dec 1, 2023
b0223c2
assembly config v0.1
vdiskg Dec 1, 2023
b518cc6
assembly config v0.2
vdiskg Dec 1, 2023
aae21a1
assembly db init
vdiskg Dec 4, 2023
4b5ebee
assembly db init fix
vdiskg Dec 4, 2023
d0fbd74
assembly sql
vdiskg Dec 4, 2023
cb48902
Merge branch 'master' into assembly
vdiskg Dec 6, 2023
7bcc979
WebSecurity
vdiskg Dec 6, 2023
baf16c2
Merge branch 'master' into assembly
vdiskg Dec 13, 2023
af7f56e
H2Function
vdiskg Dec 13, 2023
c22644a
assembly profile
vdiskg Dec 13, 2023
73d45a7
assembly session
vdiskg Dec 13, 2023
ab86efe
ddl-auto=none
vdiskg Dec 13, 2023
d248136
DataSource
vdiskg Dec 13, 2023
8caeaa2
doc
vdiskg Dec 13, 2023
b9b055a
Merge branch 'master' into assembly
vdiskg Dec 18, 2023
d1590b5
admin assembly profile
vdiskg Dec 18, 2023
3000fa8
copy assembly sql on build
vdiskg Dec 18, 2023
889943f
merge sql conflict
vdiskg Dec 18, 2023
1782d58
sql comment
vdiskg Dec 18, 2023
497fb9f
sql converter
vdiskg Dec 18, 2023
2888dbf
sql converter delta
vdiskg Dec 22, 2023
ea07f15
sql converter clean
vdiskg Dec 22, 2023
84a54cc
fix assembly sql
vdiskg Dec 22, 2023
41b010f
fix assembly sql temp
vdiskg Dec 22, 2023
074376b
Merge branch 'master' into assembly
nobodyiam Dec 23, 2023
4a6837f
fix assembly sql temp v0.2
vdiskg Dec 29, 2023
d773cd7
fix assembly sql temp v0.3
vdiskg Jan 2, 2024
7663dd3
fix assembly sql temp v0.4
vdiskg Jan 2, 2024
7930dc3
fix assembly sql temp v0.5
vdiskg Jan 2, 2024
6763f62
assembly doc
vdiskg Jan 5, 2024
1fe8c27
autoGeneratedDeclaration
vdiskg Jan 5, 2024
cc438b8
rename sql-converter module
vdiskg Jan 5, 2024
b485a29
sql-converter h2
vdiskg Jan 5, 2024
e2de672
fix database-discovery
vdiskg Jan 5, 2024
08da155
Merge branch 'assembly-temp' into assembly
vdiskg Jan 5, 2024
7fc7246
Merge branch 'master' into assembly-temp
vdiskg Jan 8, 2024
001119f
mv sql
vdiskg Jan 8, 2024
5fba666
mv sql v0.2
vdiskg Jan 8, 2024
852feff
mv sql v0.3
vdiskg Jan 8, 2024
3ce7c39
multi datasource
vdiskg Jan 12, 2024
f305489
remove table prefix
vdiskg Jan 12, 2024
34c2596
update doc
vdiskg Jan 12, 2024
224bd7a
fix init
vdiskg Jan 12, 2024
435348a
log apollo datasource initialize
vdiskg Jan 12, 2024
0397d90
fix apollo datasource initialize
vdiskg Jan 12, 2024
ee487c8
mv h2 sql
vdiskg Jan 12, 2024
e24336a
fix apollo datasource initialize v0.2
vdiskg Jan 12, 2024
31657f3
Merge branch 'assembly-temp' into assembly
vdiskg Jan 12, 2024
bbe2163
clean import
vdiskg Jan 12, 2024
d0aa029
fix sql check
vdiskg Jan 12, 2024
5d212c3
fix sql check v0.2
vdiskg Jan 12, 2024
6e4ad6d
Merge branch 'assembly-temp' into assembly
vdiskg Jan 12, 2024
497e36e
Merge branch 'master' into assembly
vdiskg Jan 15, 2024
1080e41
merge sql
vdiskg Jan 15, 2024
bce70ef
merge sql generated
vdiskg Jan 15, 2024
d0e409e
add sql test temp
vdiskg Jan 23, 2024
1313fc3
add sql test temp 2
vdiskg Jan 24, 2024
db9a48a
add sql test
vdiskg Jan 26, 2024
c8b3765
sql convert
vdiskg Jan 26, 2024
08ffbb7
fix sql-convert
vdiskg Jan 26, 2024
10f65ae
Merge branch 'master' into assembly
vdiskg Jan 26, 2024
b1e370a
CHANGES.md
vdiskg Jan 26, 2024
768c250
fix copyright
vdiskg Jan 26, 2024
4d72047
clean logger
vdiskg Feb 2, 2024
a8398e5
Merge branch 'master' into assembly
vdiskg Feb 2, 2024
4941f4f
fix order
vdiskg Feb 2, 2024
06afabb
fix h2 converter
vdiskg Feb 2, 2024
d68ed97
fix h2 converter v0.2
vdiskg Feb 2, 2024
e8b44ee
fix order v0.2
vdiskg Feb 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Apollo 2.3.0
* [Fix circular references on LdapAutoConfiguration](https://github.com/apolloconfig/apollo/pull/5055)
* [Add comment for clusters and UI display](https://github.com/apolloconfig/apollo/pull/5072)
* [Fix the issue that the length of private namespaces are mis-calculated](https://github.com/apolloconfig/apollo/pull/5078)
* [apollo assembly optimization](https://github.com/apolloconfig/apollo/pull/5035)


------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
Expand All @@ -29,7 +30,9 @@
@EnableAspectJAutoProxy
@Configuration
@PropertySource(value = {"classpath:adminservice.properties"})
@EnableAutoConfiguration
@EnableAutoConfiguration(exclude = {
UserDetailsServiceAutoConfiguration.class,
})
@EnableTransactionManagement
@ComponentScan(basePackageClasses = {ApolloCommonConfig.class,
ApolloBizConfig.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2024 Apollo Authors
*
* 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.ctrip.framework.apollo.adminservice;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Profile("assembly")
@Configuration
public class AdminServiceAssemblyConfiguration {

Check warning on line 28 in apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/AdminServiceAssemblyConfiguration.java

View check run for this annotation

Codecov / codecov/patch

apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/AdminServiceAssemblyConfiguration.java#L27-L28

Added lines #L27 - L28 were not covered by tests
@Order(101)
@Configuration
static class AdminServiceSecurityConfigurer extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();

Check failure

Code scanning / CodeQL

Disabled Spring CSRF protection High

CSRF vulnerability due to protection being disabled.
http.httpBasic();
}
}
}
28 changes: 28 additions & 0 deletions apollo-assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,34 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes/META-INF/sql/profiles</outputDirectory>
<resources>
<resource>
<directory>${project.parent.basedir}/scripts/sql/profiles</directory>
<includes>
<include>h2-default/apolloconfigdb.sql</include>
<include>h2-default/apolloportaldb.sql</include>
<include>mysql-database-not-specified/apolloconfigdb.sql</include>
<include>mysql-database-not-specified/apolloportaldb.sql</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,22 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.context.scope.refresh.RefreshScope;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class,
HibernateJpaAutoConfiguration.class, ApolloAuditAutoConfiguration.class})
@SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class,
HibernateJpaAutoConfiguration.class,
ApolloAuditAutoConfiguration.class,
})
public class ApolloApplication {

private static final Logger logger = LoggerFactory.getLogger(ApolloApplication.class);
Expand All @@ -41,39 +47,46 @@ public static void main(String[] args) throws Exception {
/**
* Common
*/
MDC.put("starting_context", "[starting:common] ");
logger.info("commonContext starting...");
ConfigurableApplicationContext commonContext =
new SpringApplicationBuilder(ApolloApplication.class).web(WebApplicationType.NONE).run(args);
logger.info(commonContext.getId() + " isActive: " + commonContext.isActive());
logger.info("commonContext [{}] isActive: {}", commonContext.getId(), commonContext.isActive());

/**
* ConfigService
*/
if (commonContext.getEnvironment().containsProperty("configservice")) {
ConfigurableApplicationContext configContext =
new SpringApplicationBuilder(ConfigServiceApplication.class).parent(commonContext)
.sources(RefreshScope.class).run(args);
logger.info(configContext.getId() + " isActive: " + configContext.isActive());
}
MDC.put("starting_context", "[starting:config] ");
logger.info("configContext starting...");
ConfigurableApplicationContext configContext =
new SpringApplicationBuilder(ConfigServiceApplication.class).parent(commonContext)
.profiles("assembly")
.sources(RefreshScope.class).run(args);
logger.info("configContext [{}] isActive: {}", configContext.getId(), configContext.isActive());

/**
* AdminService
*/
if (commonContext.getEnvironment().containsProperty("adminservice")) {
ConfigurableApplicationContext adminContext =
new SpringApplicationBuilder(AdminServiceApplication.class).parent(commonContext)
.sources(RefreshScope.class).run(args);
logger.info(adminContext.getId() + " isActive: " + adminContext.isActive());
}
MDC.put("starting_context", "[starting:admin] ");
logger.info("adminContext starting...");
ConfigurableApplicationContext adminContext =
new SpringApplicationBuilder(AdminServiceApplication.class).parent(commonContext)
.profiles("assembly")
.sources(RefreshScope.class).run(args);
logger.info("adminContext [{}] isActive: {}", adminContext.getId(), adminContext.isActive());

/**
* Portal
*/
if (commonContext.getEnvironment().containsProperty("portal")) {
ConfigurableApplicationContext portalContext =
new SpringApplicationBuilder(PortalApplication.class).parent(commonContext)
.sources(RefreshScope.class).run(args);
logger.info(portalContext.getId() + " isActive: " + portalContext.isActive());
}
MDC.put("starting_context", "[starting:portal] ");
logger.info("portalContext starting...");
ConfigurableApplicationContext portalContext =
new SpringApplicationBuilder(PortalApplication.class).parent(commonContext)
.profiles("assembly")
.sources(RefreshScope.class).run(args);
logger.info("portalContext [{}] isActive: {}", portalContext.getId(), portalContext.isActive());

MDC.clear();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Copyright 2024 Apollo Authors
#
# 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.
#
apollo.eureka.server.enabled=false
eureka.client.enabled=false
spring.cloud.discovery.enabled=false

apollo.service.registry.enabled=true
apollo.service.registry.cluster=default
apollo.service.registry.heartbeatIntervalInSecond=10

apollo.service.discovery.enabled=true
# health check by heartbeat, heartbeat time before 61s ago will be seemed as unhealthy
apollo.service.discovery.healthCheckIntervalInSecond = 61
47 changes: 47 additions & 0 deletions apollo-assembly/src/main/resources/application-github.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# Copyright 2024 Apollo Authors
#
# 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.
#
# Config DataSource
spring.config-datasource.url=jdbc:h2:mem:~/apollo-config-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE
#spring.config-datasource.username=
#spring.config-datasource.password=
spring.sql.config-init.schema-locations=@@repository@@/profiles/@@platform@@@@suffix@@/apolloconfigdb.sql
spring.sql.config-init.mode=embedded
# Portal DataSource
spring.portal-datasource.url=jdbc:h2:mem:~/apollo-portal-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE
#spring.portal-datasource.username=
#spring.portal-datasource.password=
spring.sql.portal-init.schema-locations=@@repository@@/profiles/@@platform@@@@suffix@@/apolloportaldb.sql
spring.sql.portal-init.mode=embedded

# Resolve Multi DataSource JMX name conflict
spring.jmx.unique-names=true

# H2 datasource
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.metadata_builder_contributor=com.ctrip.framework.apollo.common.jpa.SqlFunctionsMetadataBuilderContributor
spring.h2.console.enabled=true
spring.h2.console.settings.web-allow-others=true

# Sql logging
#logging.level.org.hibernate.SQL=DEBUG

# Default env
apollo.portal.envs=local

# Spring session
spring.session.store-type=none
4 changes: 4 additions & 0 deletions apollo-assembly/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
~
-->
<configuration>
<property name="CONSOLE_LOG_PATTERN"
value="${CONSOLE_LOG_PATTERN:-%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %X{starting_context}%clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
<property name="FILE_LOG_PATTERN"
value="${FILE_LOG_PATTERN:-%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- [%t] %-40.40logger{39} %X{starting_context}: %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<property name="LOG_FILE"
value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}apollo-assembly.log}" />
Expand Down
25 changes: 22 additions & 3 deletions apollo-assembly/src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,29 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
spring.datasource.url = jdbc:h2:mem:~/apolloconfigdb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1
# Config DataSource
spring.config-datasource.url=jdbc:h2:mem:~/apollo-config-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE
#spring.config-datasource.username=
#spring.config-datasource.password=
spring.sql.config-init.schema-locations=@@repository@@/profiles/@@platform@@@@suffix@@/apolloconfigdb.sql
spring.sql.config-init.mode=embedded
# Portal DataSource
spring.portal-datasource.url=jdbc:h2:mem:~/apollo-portal-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE
#spring.portal-datasource.username=
#spring.portal-datasource.password=
spring.sql.portal-init.schema-locations=@@repository@@/profiles/@@platform@@@@suffix@@/apolloportaldb.sql
spring.sql.portal-init.mode=embedded

# Resolve Multi DataSource JMX name conflict
spring.jmx.unique-names=true

# H2 datasource
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.metadata_builder_contributor=com.ctrip.framework.apollo.common.jpa.SqlFunctionsMetadataBuilderContributor
spring.h2.console.enabled = true
spring.h2.console.enabled=true
spring.h2.console.settings.web-allow-others=true
apollo.portal.env= local

# Default env
apollo.portal.envs=local
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2024 Apollo Authors
*
* 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.ctrip.framework.apollo.biz;

import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;

@Profile("assembly")
@Configuration
public class ApolloBizAssemblyConfiguration {

@Primary
@ConfigurationProperties(prefix = "spring.config-datasource")
@Bean
public static DataSourceProperties dataSourceProperties() {
return new DataSourceProperties();

Check warning on line 34 in apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/ApolloBizAssemblyConfiguration.java

View check run for this annotation

Codecov / codecov/patch

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/ApolloBizAssemblyConfiguration.java#L34

Added line #L34 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public BizDBPropertySource(final ServerConfigRepository serverConfigRepository,

@PostConstruct
public void runSqlScript() throws Exception {
if (env.acceptsProfiles(Profiles.of("h2"))) {
if (env.acceptsProfiles(Profiles.of("h2")) && !env.acceptsProfiles(Profiles.of("assembly"))) {
Resource resource = new ClassPathResource("jpa/configdb.init.h2.sql");
if (resource.exists()) {
DatabasePopulatorUtils.execute(new ResourceDatabasePopulator(resource), dataSource);
Expand Down
Loading
Loading