sofa-boot icon indicating copy to clipboard operation
sofa-boot copied to clipboard

Add configuration for local env(#861)

Open aaronlinv opened this issue 3 years ago • 8 comments

  1. 也判断下是不是 Eclipse 启动的(判断下是否能加载到 Eclipse 的 class) Eclipse 似乎并不是像 IDEA 一样使用 agent 方式启动,所以没有找到 Eclipse 的 class,参考了一些资料How to detect that code is running inside eclipse IDE,没有找到比较靠谱的判断方式,所以没有实现该功能

  2. 加个配置项,如果配了就认为是通过 IDE 启动的 增加了相关的配置项与其对应的测试类

aaronlinv avatar Sep 10 '21 18:09 aaronlinv

Hi @aaronlinv, welcome to SOFAStack community, Please sign Contributor License Agreement!

After you signed CLA, we will automatically sync the status of this pull request in 3 minutes.

sofastack-bot[bot] avatar Sep 10 '21 18:09 sofastack-bot[bot]

Thanks for your contribution! @alaneuler Can u help review this pr ?

seeflood avatar Sep 26 '21 03:09 seeflood

@aaronlinv

  1. plz format the code via mvn package
  2. we want a configuration for specifying local env, not logging (isLocalEnv returns true if setting the configuration to true)
  3. set aside the eclipse detecting as there seems no reliable way of detecting

alaneuler avatar Sep 27 '21 05:09 alaneuler

@alaneuler Thanks, only need to detect the specified environment variable in the isLocalEnv method?

aaronlinv avatar Sep 27 '21 06:09 aaronlinv

@alaneuler Thanks, only need to detect the specified environment variable in the isLocalEnv method?

To put it simple, say, users of SOFABoot add a configuration item sofa.local.env=true (just for example, you can decide the key sensibly) in application.properties, then method isLocalEnv always returns true no matter if it runs in Eclipse/IntelliJ IDEA or not.

alaneuler avatar Sep 27 '21 13:09 alaneuler

  • There is no need to modify LogEnvironmentPrepareingListener#defaultConsoleLoggers()

  • sofa.local.env=true should be read and instantiate LocalEnvUtil field

  • when use LocalEnvUtil#isLocalEnv ,

    • first you shoud read this field
    • if this field is null you should assert runs in Eclipse/IntelliJ IDEA or not.
  • reason

    • this LocalEnvUtil not only used in LogEnvironmentPrepareingListener ,this is a universal static method ,
      • example
        • if LocalEnvUtil#isLocalEnv return true , allows you to do things that are not allowed in the production environment.
  • important

    • you should instantiate this sofa.local.env=true to LocalEnvUtil Before LogEnviromnetPrepareingListener#defaultConsoleLoggers()

nogeek-cn avatar Sep 29 '21 16:09 nogeek-cn

Thanks, all very helpful, I resubmitted the code, is this ok?

aaronlinv avatar Sep 29 '21 17:09 aaronlinv

Codecov Report

Merging #877 (5c1fec3) into master (b3770f2) will increase coverage by 0.57%. The diff coverage is 16.66%.

:exclamation: Current head 5c1fec3 differs from pull request most recent head 2e22741. Consider uploading reports for the commit 2e22741 to get more accurate results Impacted file tree graph

@@             Coverage Diff              @@
##             master     #877      +/-   ##
============================================
+ Coverage     71.15%   71.72%   +0.57%     
  Complexity       36       36              
============================================
  Files           303      301       -2     
  Lines          8601     8514      -87     
  Branches       1195     1177      -18     
============================================
- Hits           6120     6107      -13     
+ Misses         1794     1723      -71     
+ Partials        687      684       -3     
Impacted Files Coverage Δ
...ava/com/alipay/sofa/boot/logging/LocalEnvUtil.java 35.71% <16.66%> (-14.29%) :arrow_down:
...ipay/sofa/runtime/api/ServiceRuntimeException.java 0.00% <0.00%> (-25.00%) :arrow_down:
...a/runtime/component/impl/ComponentManagerImpl.java 60.18% <0.00%> (-2.78%) :arrow_down:
...pay/sofa/runtime/SofaBizUninstallEventHandler.java 64.28% <0.00%> (-2.39%) :arrow_down:
...fa/runtime/service/component/ServiceComponent.java 56.16% <0.00%> (-2.28%) :arrow_down:
...y/sofa/runtime/invoke/JvmServiceTargetHabitat.java
...fa/runtime/spring/AfterBizStartupEventHandler.java
...com/alipay/sofa/runtime/SofaRuntimeProperties.java 80.00% <0.00%> (+0.83%) :arrow_up:
...m/alipay/sofa/isle/stage/ModuleLogOutputStage.java 94.93% <0.00%> (+2.53%) :arrow_up:
.../configure/SofaRuntimeConfigurationProperties.java 96.87% <0.00%> (+7.40%) :arrow_up:
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update b3770f2...2e22741. Read the comment docs.

codecov[bot] avatar Oct 08 '21 05:10 codecov[bot]

LocalEnvUtil 是作为静态类使用的,目前这种写法是无法注入配置的,你还有时间修复这段代码吗?

HzjNeverStop avatar Dec 13 '22 09:12 HzjNeverStop

LocalEnvUtil 是作为静态类使用的,目前这种写法是无法注入配置的,你还有时间修复这段代码吗?

非常抱歉,目前在忙其他的事情,没有时间修复,请将对应的 issue 分配给其他的小伙伴

aaronlinv avatar Dec 16 '22 13:12 aaronlinv