Skip to content

Commit f69cf0f

Browse files
HzjNeverStop致节致节
authored
feat:support startup endpoint (#673)
* feat:add startup endpoint * chore:update to 3.4.3-SNAPSHOT * feat:add startup endpoint * feat:update javadoc * update beanInitCost name * add application.properties for test * update test * update test * update test Co-authored-by: 致节 <[email protected]> Co-authored-by: 致节 <[email protected]>
1 parent b841cb2 commit f69cf0f

File tree

73 files changed

+1989
-78
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1989
-78
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<modelVersion>4.0.0</modelVersion>
2424
<groupId>com.alipay.sofa</groupId>
2525
<artifactId>sofa-boot-build</artifactId>
26-
<version>3.4.2</version>
26+
<version>3.4.3-SNAPSHOT</version>
2727
<packaging>pom</packaging>
2828
<name>SOFABoot Build</name>
2929
<description>SOFABoot Build</description>

sofa-boot-project/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>sofa-boot-build</artifactId>
77
<groupId>com.alipay.sofa</groupId>
8-
<version>3.4.2</version>
8+
<version>3.4.3-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

sofa-boot-project/sofa-boot-actuator-autoconfigure/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.alipay.sofa</groupId>
77
<artifactId>sofa-boot-parent</artifactId>
8-
<version>3.4.2</version>
8+
<version>3.4.3-SNAPSHOT</version>
99
<relativePath>../sofa-boot-parent</relativePath>
1010
</parent>
1111

@@ -49,6 +49,12 @@
4949
<optional>true</optional>
5050
</dependency>
5151

52+
<dependency>
53+
<groupId>com.alipay.sofa</groupId>
54+
<artifactId>startup-sofa-boot</artifactId>
55+
<optional>true</optional>
56+
</dependency>
57+
5258
<!-- Test -->
5359
<dependency>
5460
<groupId>org.springframework.boot</groupId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.alipay.sofa.boot.actuator.autoconfigure.startup;
18+
19+
import com.alipay.sofa.boot.actuator.startup.SofaBootStartupEndPoint;
20+
import com.alipay.sofa.startup.SofaStartupContext;
21+
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
22+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
23+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
24+
import org.springframework.context.annotation.Bean;
25+
import org.springframework.context.annotation.Configuration;
26+
27+
/**
28+
* @author: Zhijie
29+
* @since: 2020/7/7
30+
*/
31+
@Configuration
32+
@ConditionalOnClass(SofaStartupContext.class)
33+
public class StartupEndPointAutoConfiguration {
34+
35+
@Bean
36+
@ConditionalOnMissingBean
37+
@ConditionalOnEnabledEndpoint(endpoint = SofaBootStartupEndPoint.class)
38+
public SofaBootStartupEndPoint sofaBootStartupEndPoint() {
39+
return new SofaBootStartupEndPoint();
40+
}
41+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
22
com.alipay.sofa.boot.actuator.autoconfigure.version.VersionEndpointAutoConfiguration,\
3-
com.alipay.sofa.boot.actuator.autoconfigure.health.SofaBootHealthCheckAutoConfiguration
3+
com.alipay.sofa.boot.actuator.autoconfigure.health.SofaBootHealthCheckAutoConfiguration,\
4+
com.alipay.sofa.boot.actuator.autoconfigure.startup.StartupEndPointAutoConfiguration

sofa-boot-project/sofa-boot-actuator/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.alipay.sofa</groupId>
77
<artifactId>sofa-boot-parent</artifactId>
8-
<version>3.4.2</version>
8+
<version>3.4.3-SNAPSHOT</version>
99
<relativePath>../sofa-boot-parent</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>
@@ -37,6 +37,12 @@
3737
<optional>true</optional>
3838
</dependency>
3939

40+
<dependency>
41+
<groupId>com.alipay.sofa</groupId>
42+
<artifactId>startup-sofa-boot</artifactId>
43+
<optional>true</optional>
44+
</dependency>
45+
4046
<dependency>
4147
<groupId>com.alipay.sofa</groupId>
4248
<artifactId>runtime-sofa-boot</artifactId>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.alipay.sofa.boot.actuator.startup;
18+
19+
import com.alipay.sofa.startup.SofaStartupReporter;
20+
import org.springframework.beans.factory.annotation.Autowired;
21+
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
22+
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
23+
24+
/**
25+
* Display the time cost details used in startup
26+
*
27+
* @author: Zhijie
28+
* @since: 2020/7/7
29+
*/
30+
@Endpoint(id = "startup")
31+
public class SofaBootStartupEndPoint {
32+
33+
@Autowired
34+
SofaStartupReporter sofaStartupReporter;
35+
36+
@ReadOperation
37+
public SofaStartupReporter.SofaStartupCostModel startup() {
38+
return sofaStartupReporter.report();
39+
}
40+
}

sofa-boot-project/sofa-boot-autoconfigure/pom.xml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.alipay.sofa</groupId>
77
<artifactId>sofa-boot-parent</artifactId>
8-
<version>3.4.2</version>
8+
<version>3.4.3-SNAPSHOT</version>
99
<relativePath>../sofa-boot-parent</relativePath>
1010
</parent>
1111

@@ -60,6 +60,12 @@
6060
<optional>true</optional>
6161
</dependency>
6262

63+
<dependency>
64+
<groupId>com.alipay.sofa</groupId>
65+
<artifactId>startup-sofa-boot</artifactId>
66+
<optional>true</optional>
67+
</dependency>
68+
6369
<dependency>
6470
<groupId>org.springframework.boot</groupId>
6571
<artifactId>spring-boot-actuator</artifactId>
@@ -151,6 +157,30 @@
151157
<artifactId>hessian</artifactId>
152158
<scope>test</scope>
153159
</dependency>
160+
<dependency>
161+
<groupId>org.apache.tomcat.embed</groupId>
162+
<artifactId>tomcat-embed-core</artifactId>
163+
<version>8.5.6</version>
164+
<scope>provided</scope>
165+
</dependency>
166+
<dependency>
167+
<groupId>org.eclipse.jetty</groupId>
168+
<artifactId>jetty-server</artifactId>
169+
<version>9.2.18.v20160721</version>
170+
<scope>provided</scope>
171+
</dependency>
172+
<dependency>
173+
<groupId>org.eclipse.jetty</groupId>
174+
<artifactId>jetty-webapp</artifactId>
175+
<version>9.2.18.v20160721</version>
176+
<scope>provided</scope>
177+
</dependency>
178+
<dependency>
179+
<groupId>io.undertow</groupId>
180+
<artifactId>undertow-core</artifactId>
181+
<version>2.1.3.Final</version>
182+
<scope>provided</scope>
183+
</dependency>
154184
</dependencies>
155185

156186
</project>

sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/runtime/SofaRuntimeAutoConfiguration.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@
1616
*/
1717
package com.alipay.sofa.boot.autoconfigure.runtime;
1818

19-
import java.util.HashSet;
20-
import java.util.ServiceLoader;
21-
import java.util.Set;
22-
23-
import org.springframework.beans.factory.annotation.Value;
24-
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
25-
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
26-
import org.springframework.boot.context.properties.EnableConfigurationProperties;
27-
import org.springframework.context.annotation.Bean;
28-
import org.springframework.context.annotation.Configuration;
29-
3019
import com.alipay.sofa.runtime.SofaFramework;
3120
import com.alipay.sofa.runtime.api.client.ReferenceClient;
3221
import com.alipay.sofa.runtime.api.client.ServiceClient;
@@ -49,6 +38,16 @@
4938
import com.alipay.sofa.runtime.spring.ServiceBeanFactoryPostProcessor;
5039
import com.alipay.sofa.runtime.spring.async.AsyncTaskExecutionListener;
5140
import com.alipay.sofa.runtime.spring.aware.DefaultRuntimeShutdownAware;
41+
import org.springframework.beans.factory.annotation.Value;
42+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
43+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
44+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
45+
import org.springframework.context.annotation.Bean;
46+
import org.springframework.context.annotation.Configuration;
47+
48+
import java.util.HashSet;
49+
import java.util.ServiceLoader;
50+
import java.util.Set;
5251

5352
/**
5453
* @author xuanbei 18/3/17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.alipay.sofa.boot.autoconfigure.startup;
18+
19+
import com.alipay.sofa.startup.SofaStartupContext;
20+
import com.alipay.sofa.startup.SofaStartupProperties;
21+
import com.alipay.sofa.startup.SofaStartupReporter;
22+
import com.alipay.sofa.startup.spring.SpringContextAwarer;
23+
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
24+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
25+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
26+
import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration;
27+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
28+
import org.springframework.context.annotation.Bean;
29+
import org.springframework.context.annotation.Configuration;
30+
import org.springframework.context.annotation.Import;
31+
32+
/**
33+
* @author: Zhijie
34+
* @since: 2020/7/8
35+
*/
36+
@Configuration
37+
@AutoConfigureBefore(ServletWebServerFactoryAutoConfiguration.class)
38+
@ConditionalOnClass(SofaStartupContext.class)
39+
@EnableConfigurationProperties(SofaStartupProperties.class)
40+
@Import({ SofaStartupConfiguration.StartupTomcat.class,
41+
SofaStartupConfiguration.StartupJetty.class,
42+
SofaStartupConfiguration.StartupUndertow.class,
43+
SofaStartupConfiguration.SpringContextAware.class,
44+
SofaStartupConfiguration.IsleSpringContextAware.class,
45+
SofaStartupConfiguration.InstallStage.class })
46+
public class SofaStartupAutoConfiguration {
47+
48+
@Bean
49+
@ConditionalOnMissingBean
50+
public SofaStartupContext sofaStartupContext(SpringContextAwarer springContextAwarer,
51+
SofaStartupProperties sofaStartupProperties) {
52+
return new SofaStartupContext(springContextAwarer, sofaStartupProperties);
53+
}
54+
55+
@Bean
56+
@ConditionalOnMissingBean
57+
public SofaStartupReporter sofaStartupReporter(SofaStartupContext sofaStartupContext) {
58+
return new SofaStartupReporter(sofaStartupContext);
59+
}
60+
}

0 commit comments

Comments
 (0)