Skip to content

Commit

Permalink
[Feature] GraalVM Native Image support (Experimental). (#11365)
Browse files Browse the repository at this point in the history
  • Loading branch information
yswdqz authored Oct 30, 2023
1 parent 789df66 commit 92af797
Show file tree
Hide file tree
Showing 43 changed files with 12,167 additions and 63 deletions.
69 changes: 68 additions & 1 deletion .github/workflows/native-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
name: GraalVM Community Edition build
on:
pull_request:
push:

concurrency:
group: skywalking-graalvm-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
SW_AGENT_JDK_VERSION: 8
MAVEN_OPTS: -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.httpconnectionManager.ttlSeconds=120
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 5 # Cache restore timeout
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -37,4 +47,61 @@ jobs:
name: Upload distribution tar
with:
name: native-pre-dist
path: distribution/graal/dist
path: graal/dist
- name: Build and save docker images
run: |
make -f graal/Makefile docker.oap || make -f graal/Makefile docker.oap
docker save -o docker-images-skywalking-oap.tar skywalking/oap:latest
- name: Upload docker images
uses: actions/upload-artifact@v3
with:
name: docker-images-native
path: docker-images-skywalking-*.tar
e2e-test:
if: |
always() && ! cancelled()
name: E2E test
needs: [build]
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
test:
- name: GraalVM Native Image Agent Test
config: test/e2e-v2/cases/go/e2e.yaml
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: actions/download-artifact@v3
name: Download docker images
with:
name: docker-images-native
path: docker-images
- name: Load docker images
run: |
find docker-images -name "*.tar" -exec docker load -i {} \;
find docker-images -name "*.tar" -exec rm {} \;
- name: Cache maven repository
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('test/e2e-v2/java-test-service/**/pom.xml') }}
restore-keys: ${{ runner.os }}-maven-
- name: Prepare test services
shell: bash
run: ./mvnw -B -q -f test/e2e-v2/java-test-service/pom.xml clean package
- name: Set env var
run: |
echo "${{ matrix.test.env }}" >> $GITHUB_ENV
- name: ${{ matrix.test.name }}
uses: apache/skywalking-infra-e2e@0a5b398fc9668ccb848b16e6da4f09180955dc3e
with:
e2e-file: $GITHUB_WORKSPACE/${{ matrix.test.config }}
- uses: actions/upload-artifact@v2
if: ${{ failure() }}
name: Upload Logs
with:
name: logs
path: "${{ env.SW_INFRA_E2E_LOG_DIR }}"
40 changes: 20 additions & 20 deletions dist-material/release-docs/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ The text of each license is the standard Apache 2.0 license.
https://mvnrepository.com/artifact/com.google.inject/guice/4.1.0 Apache-2.0
https://mvnrepository.com/artifact/com.google.j2objc/j2objc-annotations/1.3 Apache-2.0
https://mvnrepository.com/artifact/com.graphql-java/java-dataloader/3.2.0 Apache-2.0
https://mvnrepository.com/artifact/com.linecorp.armeria/armeria/1.24.3 Apache-2.0
https://mvnrepository.com/artifact/com.linecorp.armeria/armeria-graphql/1.24.3 Apache-2.0
https://mvnrepository.com/artifact/com.linecorp.armeria/armeria-graphql-protocol/1.24.3 Apache-2.0
https://mvnrepository.com/artifact/com.linecorp.armeria/armeria-protobuf/1.24.3 Apache-2.0
https://mvnrepository.com/artifact/com.linecorp.armeria/armeria/1.25.0 Apache-2.0
https://mvnrepository.com/artifact/com.linecorp.armeria/armeria-graphql/1.25.0 Apache-2.0
https://mvnrepository.com/artifact/com.linecorp.armeria/armeria-graphql-protocol/1.25.0 Apache-2.0
https://mvnrepository.com/artifact/com.linecorp.armeria/armeria-protobuf/1.25.0 Apache-2.0
https://mvnrepository.com/artifact/com.orbitz.consul/consul-client/1.5.3 Apache-2.0
https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp/4.9.0 Apache-2.0
https://mvnrepository.com/artifact/com.squareup.okio/okio/2.8.0 Apache-2.0
Expand Down Expand Up @@ -295,34 +295,34 @@ The text of each license is the standard Apache 2.0 license.
https://mvnrepository.com/artifact/io.grpc/grpc-protobuf/1.53.0 Apache-2.0
https://mvnrepository.com/artifact/io.grpc/grpc-protobuf-lite/1.53.0 Apache-2.0
https://mvnrepository.com/artifact/io.grpc/grpc-stub/1.53.0 Apache-2.0
https://mvnrepository.com/artifact/io.micrometer/micrometer-commons/1.11.1 Apache-2.0
https://mvnrepository.com/artifact/io.micrometer/micrometer-core/1.11.1 Apache-2.0
https://mvnrepository.com/artifact/io.micrometer/micrometer-observation/1.11.1 Apache-2.0
https://mvnrepository.com/artifact/io.micrometer/micrometer-commons/1.11.3 Apache-2.0
https://mvnrepository.com/artifact/io.micrometer/micrometer-core/1.11.3 Apache-2.0
https://mvnrepository.com/artifact/io.micrometer/micrometer-observation/1.11.3 Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-buffer/4.1.100.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-codec/4.1.100.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-codec-dns/4.1.94.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-codec-haproxy/4.1.94.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-codec-dns/4.1.96.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-codec-haproxy/4.1.96.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-codec-http/4.1.100.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-codec-http2/4.1.100.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-codec-socks/4.1.100.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-common/4.1.100.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-handler/4.1.100.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-handler-proxy/4.1.100.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-resolver/4.1.94.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-resolver-dns/4.1.94.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-resolver-dns-classes-macos/4.1.94.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-resolver-dns-native-macos/4.1.94.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-resolver/4.1.96.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-resolver-dns/4.1.96.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-resolver-dns-classes-macos/4.1.96.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-resolver-dns-native-macos/4.1.96.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-tcnative-boringssl-static/2.0.52.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-tcnative-boringssl-static/2.0.61.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-tcnative-classes/2.0.61.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-transport/4.1.94.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-transport-classes-epoll/4.1.94.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-transport-classes-kqueue/4.1.94.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-transport/4.1.96.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-transport-classes-epoll/4.1.96.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-transport-classes-kqueue/4.1.96.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-transport-native-epoll/4.1.45.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-transport-native-epoll/4.1.94.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-transport-native-kqueue/4.1.94.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-transport-native-epoll/4.1.96.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-transport-native-kqueue/4.1.96.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-transport-native-unix-common/4.1.79.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-transport-native-unix-common/4.1.94.Final Apache-2.0
https://mvnrepository.com/artifact/io.netty/netty-transport-native-unix-common/4.1.96.Final Apache-2.0
https://mvnrepository.com/artifact/io.perfmark/perfmark-api/0.25.0 Apache-2.0
https://mvnrepository.com/artifact/io.prometheus/simpleclient/0.6.0 Apache-2.0
https://mvnrepository.com/artifact/io.prometheus/simpleclient_common/0.6.0 Apache-2.0
Expand Down Expand Up @@ -460,7 +460,7 @@ MIT licenses
The following components are provided under the MIT License. See project link for details.
The text of each license is also included in licenses/LICENSE-[project].txt.

https://npmjs.com/package/@babel/parser/v/7.22.5 7.22.5 MIT
https://npmjs.com/package/@babel/parser/v/7.23.0 7.23.0 MIT
https://npmjs.com/package/@ctrl/tinycolor/v/3.5.0 3.5.0 MIT
https://npmjs.com/package/@egjs/hammerjs/v/2.0.17 2.0.17 MIT
https://npmjs.com/package/@element-plus/icons-vue/v/1.1.4 1.1.4 MIT
Expand Down
1 change: 1 addition & 0 deletions docs/en/changes/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* Add a component ID for Netty-http (ID=151).
* Add a component ID for Fiber (ID=5021).
* BanyanDBStorageClient: Add `define(Property property, PropertyStore.Strategy strategy)` API.
* Support GraalVM native-image (Experimental).

#### UI

Expand Down
40 changes: 34 additions & 6 deletions docs/en/setup/backend/backend-graalvm.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,38 @@ The resulting program has faster startup time and lower runtime memory overhead

SkyWalking currently offers support for OAP servers running as native-image. However, please note that the OAP started in this manner does not have the same functionality as the regular OAP, and some features are not yet supported.

## Prerequisites
Before proceeding with the compilation process, it's crucial to have the GraalVM JDK installed on your machine as the native-image compilation is dependent on it.

### Installing GraalVM JDK
Refer to [GraalVM's official download page](https://www.graalvm.org/downloads/) for downloading and configuring GraalVM JDK. A convenient method is utilizing SDKMAN, which allows you to download and install GraalVM JDK with a single command:

```shell
sdk install java 17.0.9-graal
```
Upon executing the above command, SDKMAN will automatically download and install the specified version of GraalVM JDK, preparing your environment for the subsequent native-image compilation process.

### Installing Native Image
In some download methods, the Native Image component is not automatically installed and needs to be downloaded separately. Users can download this component by executing the following command:

```shell
gu install native-image
```

This command utilizes the GraalVM Updater (gu) to install the Native Image component, ensuring the environment is properly set up for native-image compilation.

## Compile Guide
Notice: If you are not familiar with the compilation process, please read [How-to-build](https://skywalking.apache.org/docs/main/next/en/guides/how-to-build/) first.
Notice: If you are not familiar with the compilation process, please read [How-to-build](../../guides/How-to-build.md) first.

The native-image compilation is not enabled by default. To enable it, we need to activate `native` profile during compilation, such as:

```shell

./mvnw -backend,naative clean package -Dmaven.test.skip
./mvnw -Pbackend,native clean package -Dmaven.test.skip

```

Then, 2 packages are in `distribution/graal/dist`,
Then, 2 packages are in `graal/dist`,
As this is an experimental feature, a package named `apache-skywalking-apm-native-pre-bin.tar.gz` is a tarball for GraalVMization friendly, including original classes to be compiled by GraalVM.
The package named `apache-skywalking-apm-native-bin.tar.gz` includes the final compiled native binary, relative configuration files, and booting shells. Read `Package Structure` doc for more details.

Expand All @@ -30,7 +50,7 @@ SkyWalking’s native-image distribution package consists of the following parts

* bin/cmd scripts: Located in the /bin folder. Includes startup Linux shell and Windows cmd scripts for the backend server.

* Backend config: Located in the /config folder. Includes settings files of the backend. Running native-image does not require additional configuration, so you can refer to [backend-setup](https://skywalking.apache.org/docs/main/next/en/setup/backend/backend-setup/) to learn how to configure it.
* Backend config: Located in the /config folder. Includes settings files of the backend. Running native-image does not require additional configuration, so you can refer to [backend-setup](backend-setup.md) to learn how to configure it.

* Native image executable: Located in /image folder. It can be run directly, but it is not recommended to do so, as the absence of some environment variables can lead to startup failure.

Expand All @@ -45,5 +65,13 @@ we can successfully start SkyWalking-oap.
## Differences and TODO
With native-image, some features are not yet supported.

1. [LAL](https://skywalking.apache.org/docs/main/next/en/concepts-and-designs/lal/), [MAL](https://skywalking.apache.org/docs/main/next/en/concepts-and-designs/mal/), and some other features related to them are not supported at the moment.
2. The [OAL](https://skywalking.apache.org/docs/main/next/en/concepts-and-designs/oal/) files are used in the compiling stage, which means that users would not see these files inside the native image package, and can't change it. Consider recompiling and packaging from the source codes including your OAL file changes.
1. [LAL](../../concepts-and-designs/lal.md), [MAL](../../concepts-and-designs/mal.md), and some other features related to them are not supported at the moment.
2. The [OAL](../../concepts-and-designs/oal.md) files are used in the compiling stage, which means that users would not see these files inside the native image package, and can't change it. Consider recompiling and packaging from the source codes including your OAL file changes.

## Current Limitations
Native-image supports reflection and other dynamic features through some JSON-formatted configuration files. SkyWalking currently provides a set of configuration files for basic support. You can find them [here](../../../../graal/graal-server-starter/src/main/resources/META-INF/native-image/main).

For now, these configuration files do not support all runtime environments (but will be fully supported in the future). Therefore, in other environments, users may need to generate the configuration files required by native-image on their own.

SkyWalking uses [native build tools](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html) to generate native-image. Additionally, GraalVM provides an agent to assist in generating configuration files. Therefore, users can generate the required configuration files by referring to [native build tools agent guide](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html#agent-support).

49 changes: 49 additions & 0 deletions graal/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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.

SHELL := /bin/bash -o pipefail

SW_GRAAL_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
CONTEXT = ${SW_GRAAL_ROOT}/dist
DIST ?= apache-skywalking-apm-native-bin.tar.gz
CLI_VERSION ?= 0.12.0 # CLI version inside OAP image should always use an Apache released artifact.

HUB ?= skywalking

TAG ?= latest

DOCKER_BUILD_TOP:=${CONTEXT}/docker_build

NAME := oap

LOAD_OR_PUSH = --load

BUILD_ARGS := $(BUILD_ARGS) --build-arg DIST=$(DIST) --build-arg SKYWALKING_CLI_VERSION=$(CLI_VERSION)

docker.% push.docker.%: $(CONTEXT)/$(DIST) $(SW_GRAAL_ROOT)/docker/%/*
$(DOCKER_RULE)

define DOCKER_RULE
mkdir -p $(DOCKER_BUILD_TOP)/$(NAME)
cp -r $^ $(DOCKER_BUILD_TOP)/$(NAME)
docker buildx create --use --driver docker-container --name skywalking_main > /dev/null 2>&1 || true
docker buildx build $(PLATFORMS) $(LOAD_OR_PUSH) \
--no-cache $(BUILD_ARGS) \
-t $(HUB)/$(NAME):$(TAG) \
-t $(HUB)/$(NAME):latest \
$(DOCKER_BUILD_TOP)/$(NAME)
docker buildx rm skywalking_main || true
endef
18 changes: 16 additions & 2 deletions graal/apache-skywalking-native-apm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,28 @@
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>dist</id>
<id>dist-native-pre</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>apache-skywalking-apm-native-pre-bin</finalName>
<descriptors>
<descriptor>${project.basedir}/src/main/assembly/binary.xml</descriptor>
<descriptor>${project.basedir}/src/main/assembly/binary-native-pre.xml</descriptor>
</descriptors>
</configuration>
</execution>
<execution>
<id>dist-native</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>apache-skywalking-apm-native-bin</finalName>
<descriptors>
<descriptor>${project.basedir}/src/main/assembly/binary-native.xml</descriptor>
</descriptors>
</configuration>
</execution>
Expand All @@ -95,6 +108,7 @@
<configuration>
<target>
<copy file="${project.build.directory}/apache-skywalking-apm-native-pre-bin.tar.gz" tofile="${project.basedir}/../dist/apache-skywalking-apm-native-pre-bin.tar.gz" overwrite="true" />
<copy file="${project.build.directory}/apache-skywalking-apm-native-bin.tar.gz" tofile="${project.basedir}/../dist/apache-skywalking-apm-native-bin.tar.gz" overwrite="true" />
</target>
</configuration>
</execution>
Expand Down
Loading

0 comments on commit 92af797

Please sign in to comment.