-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[AI-8th] add SofaDiagnosticEndpoint for runtime diagnostics #1411
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
Open
kuleat
wants to merge
8
commits into
sofastack:master
Choose a base branch
from
kuleat:feature/sofa-diagnostic-endpoint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a8f593e
feat: add SofaDiagnosticEndpoint for runtime diagnostics
kuleat 17b0e49
trigger CLA check
kuleat 5b049c2
add diagnostic endpoint command tests
kuleat 47c3345
remove spring security
kuleat 195565a
Make sofa diagnostic read-only by default
kuleat f3769f5
Remove service-metadata
kuleat 3d929cd
Use Spring Boot ProcessInfo for memory stats
kuleat 57479a3
Remove diagnostic write operations
kuleat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
.../sofa/boot/actuator/autoconfigure/diagnostic/SofaDiagnosticEndpointAutoConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package com.alipay.sofa.boot.actuator.autoconfigure.diagnostic; | ||
|
|
||
| import com.alipay.sofa.boot.actuator.diagnostic.SofaDiagnosticEndpoint; | ||
| import com.alipay.sofa.boot.autoconfigure.runtime.SofaRuntimeAutoConfiguration; | ||
| import com.alipay.sofa.common.thread.ThreadPoolGovernor; | ||
| import com.alipay.sofa.rpc.context.RpcRuntimeContext; | ||
| import com.alipay.sofa.runtime.spi.component.SofaRuntimeContext; | ||
| import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint; | ||
| import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
| import org.springframework.context.ApplicationContext; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.security.web.SecurityFilterChain; | ||
|
|
||
| /** | ||
| * {@link EnableAutoConfiguration Auto-configuration} for {@link SofaDiagnosticEndpoint}. | ||
| * | ||
| * @author xiaosiyuan | ||
| * @version SofaDiagnosticEndpointAutoConfiguration.java, v 0.1 2026年04月01日 xiaosiyuan Exp $ | ||
| */ | ||
| @AutoConfiguration(after = SofaRuntimeAutoConfiguration.class) | ||
| @ConditionalOnClass({ SofaRuntimeContext.class, RpcRuntimeContext.class }) | ||
| @ConditionalOnBean(SofaRuntimeContext.class) | ||
| @ConditionalOnAvailableEndpoint(endpoint = SofaDiagnosticEndpoint.class) | ||
| public class SofaDiagnosticEndpointAutoConfiguration { | ||
|
|
||
| @Bean | ||
| @ConditionalOnMissingBean | ||
| @ConditionalOnProperty(prefix = "management.endpoint.sofa-diagnostic", name = "sensitive", havingValue = "false") | ||
| public SofaDiagnosticEndpoint publicSofaDiagnosticEndpoint(SofaRuntimeContext sofaRuntimeContext, | ||
| ApplicationContext applicationContext) { | ||
| return createEndpoint(sofaRuntimeContext, applicationContext); | ||
| } | ||
|
|
||
| @Bean | ||
| @ConditionalOnMissingBean | ||
| @ConditionalOnClass(SecurityFilterChain.class) | ||
| @ConditionalOnProperty(prefix = "management.endpoint.sofa-diagnostic", name = "sensitive", havingValue = "true", matchIfMissing = true) | ||
| public SofaDiagnosticEndpoint secureSofaDiagnosticEndpoint(SofaRuntimeContext sofaRuntimeContext, | ||
| ApplicationContext applicationContext) { | ||
| return createEndpoint(sofaRuntimeContext, applicationContext); | ||
| } | ||
|
kuleat marked this conversation as resolved.
Outdated
|
||
|
|
||
| private SofaDiagnosticEndpoint createEndpoint(SofaRuntimeContext sofaRuntimeContext, | ||
| ApplicationContext applicationContext) { | ||
| return new SofaDiagnosticEndpoint(sofaRuntimeContext, ThreadPoolGovernor.getInstance(), | ||
| applicationContext); | ||
| } | ||
| } | ||
75 changes: 75 additions & 0 deletions
75
.../sofa/boot/actuator/autoconfigure/diagnostic/SofaDiagnosticSecurityAutoConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package com.alipay.sofa.boot.actuator.autoconfigure.diagnostic; | ||
|
|
||
| import com.alipay.sofa.boot.actuator.diagnostic.SofaDiagnosticEndpoint; | ||
| import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest; | ||
| import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration; | ||
| import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; | ||
| import org.springframework.boot.autoconfigure.security.ConditionalOnDefaultWebSecurity; | ||
| import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; | ||
| import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration; | ||
| import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.security.config.Customizer; | ||
| import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
| import org.springframework.security.web.SecurityFilterChain; | ||
|
|
||
| /** | ||
| * {@link EnableAutoConfiguration Auto-configuration} for securing the | ||
| * {@link SofaDiagnosticEndpoint sofa-diagnostic} actuator endpoint. | ||
| * | ||
| * <p>Requires HTTP Basic authentication by default ({@code sensitive=true}). | ||
| * Set {@code management.endpoint.sofa-diagnostic.sensitive=false} to allow public access. | ||
| * Backs off when the application defines its own {@link SecurityFilterChain}. | ||
| * | ||
| * @author xiaosiyuan | ||
| * @version SofaDiagnosticSecurityAutoConfiguration.java, v 0.1 2026年04月03日 xiaosiyuan Exp $ | ||
| */ | ||
| @AutoConfiguration(before = { SecurityAutoConfiguration.class, | ||
| UserDetailsServiceAutoConfiguration.class, | ||
| ManagementWebSecurityAutoConfiguration.class }) | ||
| @ConditionalOnDefaultWebSecurity | ||
| @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) | ||
| @EnableConfigurationProperties(SofaDiagnosticSecurityProperties.class) | ||
| public class SofaDiagnosticSecurityAutoConfiguration { | ||
|
kuleat marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * Security filter chain for the {@code sofa-diagnostic} actuator endpoint only. | ||
| */ | ||
| @Bean | ||
| public SecurityFilterChain sofaDiagnosticSecurityFilterChain(HttpSecurity http, | ||
| SofaDiagnosticSecurityProperties properties) | ||
| throws Exception { | ||
| http.securityMatcher(EndpointRequest.to(SofaDiagnosticEndpoint.class)) | ||
| .authorizeHttpRequests(auth -> { | ||
| if (properties.isSensitive()) { | ||
| auth.anyRequest().authenticated(); | ||
|
kuleat marked this conversation as resolved.
Outdated
|
||
| } else { | ||
| auth.anyRequest().permitAll(); | ||
| } | ||
| }) | ||
| // Programmatic REST endpoint; CSRF disabled. | ||
| .csrf(csrf -> csrf.disable()); | ||
| if (properties.isSensitive()) { | ||
| http.httpBasic(Customizer.withDefaults()); | ||
| } | ||
| return http.build(); | ||
| } | ||
| } | ||
43 changes: 43 additions & 0 deletions
43
.../alipay/sofa/boot/actuator/autoconfigure/diagnostic/SofaDiagnosticSecurityProperties.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package com.alipay.sofa.boot.actuator.autoconfigure.diagnostic; | ||
|
|
||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
|
||
| /** | ||
| * Configuration properties for {@code sofa-diagnostic} endpoint security. | ||
| * | ||
| * @author xiaosiyuan | ||
| * @version SofaDiagnosticSecurityProperties.java, v 0.1 2026年04月03日 xiaosiyuan Exp $ | ||
| */ | ||
| @ConfigurationProperties("management.endpoint.sofa-diagnostic") | ||
| public class SofaDiagnosticSecurityProperties { | ||
|
|
||
| /** | ||
| * Whether to require HTTP Basic authentication. {@code true} (default): auth required; | ||
| * {@code false}: publicly accessible. | ||
| */ | ||
| private boolean sensitive = true; | ||
|
|
||
| public boolean isSensitive() { | ||
| return sensitive; | ||
| } | ||
|
|
||
| public void setSensitive(boolean sensitive) { | ||
| this.sensitive = sensitive; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
.../boot/actuator/autoconfigure/diagnostic/SofaDiagnosticEndpointAutoConfigurationTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package com.alipay.sofa.boot.actuator.autoconfigure.diagnostic; | ||
|
|
||
| import com.alipay.sofa.boot.actuator.diagnostic.SofaDiagnosticEndpoint; | ||
| import com.alipay.sofa.boot.autoconfigure.runtime.SofaRuntimeAutoConfiguration; | ||
| import com.alipay.sofa.rpc.context.RpcRuntimeContext; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
| import org.springframework.boot.test.context.FilteredClassLoader; | ||
| import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| /** | ||
| * Tests for {@link SofaDiagnosticEndpointAutoConfiguration}. | ||
| * | ||
| * @author xiaosiyuan | ||
| * @version SofaDiagnosticEndpointAutoConfigurationTests.java, v 0.1 2026年04月02日 xiaosiyuan Exp $ | ||
| */ | ||
| public class SofaDiagnosticEndpointAutoConfigurationTests { | ||
|
|
||
| private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() | ||
| .withConfiguration(AutoConfigurations | ||
| .of(SofaDiagnosticEndpointAutoConfiguration.class, | ||
| SofaRuntimeAutoConfiguration.class)); | ||
|
|
||
| @Test | ||
| void runShouldHaveEndpointBean() { | ||
| this.contextRunner.withPropertyValues( | ||
| "management.endpoints.web.exposure.include=sofa-diagnostic") | ||
| .run((context) -> assertThat(context).hasSingleBean(SofaDiagnosticEndpoint.class)); | ||
| } | ||
|
|
||
| @Test | ||
| void runWhenNotExposedShouldNotHaveEndpointBean() { | ||
| this.contextRunner | ||
| .run((context) -> assertThat(context).doesNotHaveBean(SofaDiagnosticEndpoint.class)); | ||
| } | ||
|
|
||
| @Test | ||
| void runWhenRpcRuntimeContextClassMissingShouldNotHaveEndpointBean() { | ||
| this.contextRunner.withClassLoader(new FilteredClassLoader(RpcRuntimeContext.class)) | ||
| .withPropertyValues("management.endpoints.web.exposure.include=*") | ||
| .run((context) -> assertThat(context).doesNotHaveBean(SofaDiagnosticEndpoint.class)); | ||
| } | ||
|
|
||
| @Test | ||
| void runWhenEnabledPropertyIsFalseShouldNotHaveEndpointBean() { | ||
| this.contextRunner.withPropertyValues("management.endpoint.sofa-diagnostic.enabled:false") | ||
| .withPropertyValues("management.endpoints.web.exposure.include=*") | ||
| .run((context) -> assertThat(context).doesNotHaveBean(SofaDiagnosticEndpoint.class)); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.