玖叶教程网

前端编程开发入门

Skywalking入门-源码编译

2022-03-29

github下载最新代码,是9.0.0-SNAPSHOT

下载源码

git clone --recurse-submodules https://github.com/apache/skywalking.git

或

git clone https://github.com/apache/skywalking.git
cd skywalking/
git submodule init
git submodule update


编译源码

源码可以分为几个部分独立的编译打包:

  1. agent:javaAgent部分
  2. ui:web ui部分
  3. backend:OAPServer部分
  4. dist:压缩打包


只处理指定部分的源码 通过-P参数指定,如:

mvn clean package -Pagent -Dmaven.test.skip=true//只处理 javaAgent部分,这在调试Agent的时候就减少许多时间
mvn package -Pbackend,dist -Dmaven.test.skip=true//只处理OapServer并打包压缩
mvn package -Pui,dist -Dmaven.test.skip=true//只处理UI并打包压缩
mvn package -Pagent,dist -Dmaven.test.skip=true//只处理 javaAgent 并打包压缩


处理全部源码,这几部分将全部被包含,这样会在编译UI的时候遇到node和npm的问题。

mvn package 


如果要要编译全部源码,会有几个问题,原因是skywalking中的前端项目是vue开发的,需要node和npm下载和初始化,是通过frontend-maven-plugin来完成的,因为默认下载地址网络不通的问题,需修改为淘宝的下载地址。
在apm-webapp项目下的pom.xml文件里,在frontend-maven-plugin的配置中将node 和 npm 的相关地址调整为淘宝的。

<configuration>
	<arguments>install --registry=https://registry.npm.taobao.org/</arguments>
</configuration>


最终效果如下:

<plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>${frontend-maven-plugin.version}</version>
                <configuration>
                    <workingDirectory>${ui.path}</workingDirectory>
                    <nodeVersion>v16.14.0</nodeVersion>
                </configuration>
                <executions>
                    <execution>
                        <id>install node and npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>npm install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>install --registry=https://registry.npm.taobao.org/</arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>npm run build</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>run build</arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>


处理好frontend-maven-plugin插件后,即可编译Skywalking的源码

cd skywalking/
mvn clean -Dmaven.test.skip=true compile


启动OAPServer

运行oap-server模块下的server-start-es7(我使用的是es7)模块中中的OAPServerStartUp这个类的main方法来启动OAPServer

如有如下类似问题:

java: package org.apache.skywalking.oap.server.configuration.service does not exist

java: package ConfigurationServiceGrpc does not exist

java: package org.apache.skywalking.apm.network.common.v3 does not exist

java: package Command does not exist

是因为有跟一些自动生成的代码没有加入到工程的源码清单中,需要将以下几处生成的代码目录标记为源码目录(Generated Sources Root)。


1、apm-skywalking\oap-server\server-configuration\grpc-configuration-sync\target\generated-sources\protobuf 目录下,的 [grpc-java] 和 [java] 这两个目录Mark Directory as -> Genenated Sources Root

2、apm-skywalking\apm-protocol\apm-network\target\generated-sources\protobuf 目录下,的 [grpc-java] 和 [java] 这两个目录Mark Directory as -> Genenated Sources Root
3、apm-skywalking\oap-server\server-core\target\generated-sources\protobuf 目录下,的 [grpc-java] 和 [java] 这两个目录Mark Directory as -> Genenated Sources Root

4、apm-skywalking/oap-server/oal-grammar/target/generated-sources/antlr4 目录下,的 [antlr4]这个目录Mark Directory as -> Genenated Sources Root


如此操作后代码可正常运行。

启动UI

运行 apm-webapp 模块的 ApplicationStartUp这个类的main方法,启动 SkyWalking UI 。

浏览器输入 http://127.0.0.1:8080,进入Skywalking UI的主页面。

配置代码规范检查

skywalking中的使用CheckStyle做代码规范检查,在编译我们变更的代码时可能会遇到如下提示:

[INFO] There are 7 errors reported by Checkstyle 8.19 with D:\work\apm-skywalking/apm-checkstyle/checkStyle.xml ruleset.
[ERROR] src\main\java\org\apache\skywalking\apm\plugin\tair\v2\DefaultTairManagerMethodInterceptor.java:[39] (whitespace) EmptyLineSeparator: 'METHOD_DE
F' has more than 1 empty lines before.
[ERROR] src\main\java\org\apache\skywalking\apm\plugin\tair\v2\DefaultTairManagerMethodInterceptor.java:[42] (regexp) RegexpSingleline: Not allow chines
e character !
[ERROR] src\main\java\org\apache\skywalking\apm\plugin\tair\v2\DefaultTairManagerMethodInterceptor.java:[49] (regexp) RegexpSingleline: Not allow chines
e character !
[ERROR] src\main\java\org\apache\skywalking\apm\plugin\tair\v2\DefaultTairManagerMethodInterceptor.java:[58] (whitespace) EmptyLineSeparator: There is m
ore than 1 empty line one after another.
[ERROR] src\main\java\org\apache\skywalking\apm\plugin\tair\v2\define\DefaultTairManagerInstrumentation.java:[29,15] (imports) UnusedImports: Unused imp
ort - net.bytebuddy.matcher.ElementMatchers.named.
[ERROR] src\main\java\org\apache\skywalking\apm\plugin\tair\v2\define\DefaultTairManagerInstrumentation.java:[49] (whitespace) EmptyLineSeparator: 'METH
OD_DEF' has more than 1 empty lines after.
[ERROR] src\main\java\org\apache\skywalking\apm\plugin\tair\v2\define\DefaultTairManagerInstrumentation.java:[49] (whitespace) EmptyLineSeparator: 'METH
OD_DEF' has more than 1 empty lines before.


因为skywalking的编译比较耗时,通过编译来检查代码是否规范,就太浪费时间了,最好在idea中安装配置一下CheckStyle插件,贴出我参考的一篇CheckStyle使用,若您觉得不合适,可自己另行寻找合适的资料。

idea中添加的skywalking中内置的本地规则文件xxx\apm-skywalking/apm-checkstyle/checkStyle.xml。

接下来就可以深入研究skywalking了。



作者:rock_fish
链接:https://www.jianshu.com/p/1ed33534590d
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言