Skip to content

Commit

Permalink
[api] add etrace-api module and fix codefactor (etrace-io#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobke authored Nov 17, 2020
1 parent 7cd1d09 commit 1ce8c02
Show file tree
Hide file tree
Showing 320 changed files with 26,882 additions and 472 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Deploy To Central Maven

on:
release:
types: [created]
types: [ created ]

jobs:
publish:
Expand Down
26 changes: 13 additions & 13 deletions .github/workflows/maven-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ name: Mvn Test
on:
push:
branches:
- master
- ci
- master
- ci
pull_request:
branches:
- master
- ci
- master
- ci

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Unit Test
run: mvn -B test -Punit-test
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Unit Test
run: mvn -B test -Punit-test
132 changes: 79 additions & 53 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
# For Maintainers of this project
# For Contributor/Maintainers

## Set up your local development environment
Following contents help you to build your local development environment.

1. set your git config. (suggest you set your email to [github private email address](https://github.com/settings/emails)):
## 1. Download and install requirements.

1. install [Docker](https://www.docker.com/products/docker-desktop).
2. set up your Java development environment.
3. set up your Maven environment.

## 2. Set up your local development environment

1. set your git config. (Setting your email as [github private email address](https://github.com/settings/emails) is one good practise.):

```
git config user.name $YOUR_GITHUB_NAME
git config user.email $YOUR_GITHUB_EMAIL
# to double check config
git config --local -l
# sign your code with GPG
# sign your code with GPG. GPG sign is optional but strongly recommended.
git config commit.gpgsign true
```

1. install [Docker](https://www.docker.com/products/docker-desktop)
2. run docker compose file: `docker-compose up`. This will start up following images:
2. config your hosts in `/etc/hosts`

- kafka
- zookeeper
- hbase
- hdfs
```
127.0.0.1 kafka hbase proemtheus mysql zookeeper
```

3. to remove all local images, run `docker-compose down`.
That's all. Then follow the guidelines in README to run _ETrace_ project.

## Deploy to OSSRH (Open Source Software Repository Host)
Feel free to fork the project and push your request!

Following contents will lead you to install and configure your settings to deploy this project to OSSRH,
who will automatically synchronize your repositories to Central Maven Repository.
## 3. Set up `GPG`
GPG sign validate you codes and contribute. It's not mandatory but strongly recommended.

#### Step one: How to set up `PGP` signature to deploy to Central Maven Repository
[Signing commits](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/signing-commits) doc on github explained how to sign the commits.

Take this article for [reference](https://central.sonatype.org/pages/working-with-pgp-signatures.html#distributing
-your-public-key):
[GPG Suite](https://gpgtools.org/) is a useful to maintain GPG key on MacOS.

Take this article for [reference](https://central.sonatype.org/pages/working-with-pgp-signatures.html#distributing-your-public-key):

1. install [gnupg](https://formulae.brew.sh/formula/gnupg): `brew install gpg` .
2. generate a key pair: `gpg --gen-key`. In the interactive, it require you a passphrase. Write it down, you'll sign
Expand All @@ -44,54 +51,78 @@ gpg --keyserver hkp://keys.gnupg.net --send-keys YOUR_KEY_ID
gpg --keyserver hkp://pool.sks-keyservers.net --send-keys YOUR_KEY_ID
```

[GPG Suite](https://gpgtools.org/) is a useful to maintain GPG key on MacOS.
[Signing commits]() doc on github explained how to sign the commits.
---

#### Step two: register an OSSRH account and configure to maven setting
# Continues Integration

The first, register a [JIRA account](https://issues.sonatype.org/secure/Signup!default.jspa).
Then inform the maintainer of this project with your username. Then a new issue about allowing you to
push the repository will be initiated and wait for official approval.
This part explain how _ETrace_ project run [Continues Integration].
Default, test is ignored to simplify coding progress,
but this [github workflow](https://github.com/etrace-io/etrace/blob/master/.github/workflows/maven-test.yml) will test every commit.

Then that issue is resolved. add following to your maven 'setting.xml':
## Unit Test
Run integration test: `mvn verify -P unit-test`.

## Integration test

Current to run integration test: `mvn verify -P integration-test`.

Another way to run integration test: [Maven Failsafe Plugin](http://maven.apache.org/surefire/maven-failsafe-plugin/usage.html) (not involved yet)

---
# Deploy component to Central Maven Repository

## automatically upload to Central Maven Repository

1. Upgrade Release Version

```
<server>
<id>ossrh</id>
<username>YOUR_USERNAME</username>
<password>YOUR_PASSWORD</password>
</server>
mvn --batch-mode release:update-versions -DdevelopmentVersion=0.0.1-SNAPSHOT -DautoVersionSubmodules=true
```

#### Step three: run and deploy

Simply run `mvn clean deploy -Possrh`. it should work!
2. Then commit code and pull the request.

3. On _ETrace_ github page, [create one release](https://github.com/etrace-io/etrace/releases/new).
Then corresponding [github workflow](https://github.com/etrace-io/etrace/blob/master/.github/workflows/maven-deploy.yml)
will do the rest -- upload to Central Maven Repository automatically.

## Run the 'Release' Progress
## manual upload to Central Maven Repository
Sometime, you may want to deploy from your local machine (if you're the maintainer of this project).

This project have include the [maven-release-plugin](https://maven.apache.org/maven-release/maven-release-plugin/index.html) to reduce the repetitive and manual work。
1. Prepare your environment: register an OSSRH account and configure to maven setting

1. run `mvn release:prepare -DautoVersionSubmodules=true`
2. run `mvn release:perform -Possrh`
The first, register a [JIRA account](https://issues.sonatype.org/secure/Signup!default.jspa).
Then inform the maintainer of this project with your username. Then a new issue about allowing you to
push the repository will be initiated and wait for the official approval.

run `mvn release:rollback` if something goes wrong in the progress. And `mvn release:clean` to remove all generated files by `release:prepare`.
When that issue resolved, add following settings to your maven 'setting.xml':

By the way, this plugin provide an easy way to update all POM version in a recursive way:
```
<server>
<id>ossrh</id>
<username>YOUR_JIRA_USERNAME</username>
<password>YOUR_JIRA_PASSWORD</password>
</server>
```
2. Upgrade Release Version
```
mvn --batch-mode release:update-versions -DdevelopmentVersion=0.0.1-SNAPSHOT -DautoVersionSubmodules=true
```
3. Then commit code and pull the request.

## How to update licence header to file

run `mvn license:update-file-header` command.

## Integration test
4. This project have included the [maven-release-plugin](https://maven.apache.org/maven-release/maven-release-plugin/index.html) to reduce the repetitive and manual work。

1. run `mvn release:prepare -DautoVersionSubmodules=true`
2. run `mvn release:perform -Possrh`

run `mvn release:rollback` if something goes wrong in the progress. And `mvn release:clean` to remove all generated files by `release:prepare`.

Current to run integration test: `mvn verify -P integration-test`.
5. Simply run `mvn clean deploy -Possrh`. it should work!

Another way to run integration test: [Maven Failsafe Plugin](http://maven.apache.org/surefire/maven-failsafe-plugin/usage.html) (not applied right now)
---
# Related background information about Dev

## How to update licence header to file
run `mvn license:update-file-header` command.

## Spring security

Expand All @@ -101,14 +132,9 @@ Another way to run integration test: [Maven Failsafe Plugin](http://maven.apache

## Spring Data - ignore the parameter if it has a null value

Based on the answer on [StackOverflow](https://stackoverflow.com/questions/43780226/spring-data-ignore-parameter-if
-it-has-a-null-value/43781418), this project adopt **[Example](https://docs.spring.io/spring-data/jpa/docs/current
/reference/html/#query-by-example.introduction)** to handle nullable parameter in db query.
Based on the answer on [StackOverflow](https://stackoverflow.com/questions/43780226/spring-data-ignore-parameter-if-it-has-a-null-value/43781418),
this project adopt **[Example](https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#query-by-example.introduction)** to handle nullable parameter in db query.

Go to io/etrace/api/service/DashboardService.java:52 for reference.

Also, keep watching Jira issue [Improve handling of null query method parameter values](https://jira.spring.io/browse/DATAJPA-209) and hope official team
could support this via annotation.



Also, keep watching Jira issue [Improve handling of null query method parameter values](https://jira.spring.io/browse/DATAJPA-209) and hope official team could support this via annotation.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@

# Introduce

# How to run _ETrace_

1. Requirement:
1. Jave 8
2. Maven 3.6.0+
3. Docker

2. Run the shell `local_dev.sh`. Follow the instruction to run _ETrace_ and related dependencies in Docker.
11 changes: 11 additions & 0 deletions docker-compose-etrace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ services:
networks:
- backend

api:
build:
context: ./etrace-api
dockerfile: Dockerfile
image: etrace-api:local
container_name: etrace_api
ports:
- 8080:8080
networks:
- backend

stream:
build:
context: ./etrace-stream/stream-container
Expand Down
4 changes: 3 additions & 1 deletion docker-compose-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ services:
- 33060:33060
volumes:
- ./temp/mysql:/var/lib/mysql
restart: always
# Initializing a fresh instance: https://hub.docker.com/_/mysql/
- ./etrace-api/mysql:/docker-entrypoint-initdb.d/:ro
# restart: always
networks:
- backend
#
Expand Down
19 changes: 6 additions & 13 deletions etrace-agent/src/main/java/io/etrace/agent/Trace.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@
/**
* The main api of trace.
* <p>
* 1. wiki link: http://wiki.ele.to:8090/pages/viewpage.action?pageId=47703803 2. add javadoc on each api.
* <p>
* Limitation: Considering the trade-off between convenience of Trace api and the resource usage of agent application,
* there are some default limitation on the length of names, the size of tags, the number of one Transaction's children
* and etc. For example, if the length or the size exceeds the threshold, the excessive part will be ignored. Finally,
* if you encounter any problems, send email to arch.etrace@ele.me for help.
* if you encounter any problems, go to https://github.com/etrace-io/etrace/issues for help
* <p>
* As for string length, when the size more than max size,it will be String.substring(0, maxSize). -- Trace: ---- type:
* 256 char ---- name: 512 char ---- status: 64 char ---- data: 2 * 1024 char(default), adjustable ---- tag name: 64
Expand Down Expand Up @@ -125,9 +123,8 @@ public static int getTCPMessageSenderQueueSize() {
*
* @param type event type
* @param name event name
* @return me.ele.arch.etrace.common.modal.Event
* <p>
* 废弃。不如使用logEvent方便。
* <p>
* 废弃。不如使用logEvent方便。
*/
@Deprecated
public static Event newEvent(String type, String name) {
Expand Down Expand Up @@ -191,9 +188,9 @@ public static void logError(Throwable throwable, Map<String, String> tags) {
/**
* create a new event, then set the message and the throwable stack information, finally complete.
* <p>
* -- Event Type: if throwable instanceof me.ele.contract.exception.ServiceException : type = "BusinessException"
* else if throwable instanceof java.lang.Error : type = "Error" else if throwable instanceof
* java.lang.RuntimeException : type = "RuntimeException" else type = "Exception"
* -- Event Type: if throwable instanceof ServiceException : type = "BusinessException" else if throwable instanceof
* java.lang.Error : type = "Error" else if throwable instanceof java.lang.RuntimeException : type =
* "RuntimeException" else type = "Exception"
* <p>
* -- Event Name: name = throwable.getClass().getName()
* <p>
Expand Down Expand Up @@ -221,7 +218,6 @@ public static void logError(String message, Throwable throwable, Map<String, Str
*
* @param type the type
* @param name the name
* @return me.ele.arch.etrace.common.modal.Transaction
*/
public static Transaction newTransaction(String type, String name) {
return trace.producer.newTransaction(type, name);
Expand Down Expand Up @@ -277,9 +273,6 @@ public static String getCurrentRequestId() {
}

/**
* more detail about RpcId, refer to :http://wiki.ele.to:8090/pages/viewpage.action?pageId=62202413
* "RequestId与RpcId说明"
*
* @return {@link String}
*/
public static String getRpcId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ public void importContext(TraceContext ctx) {
if (ctx != null && ctx.getCtx() instanceof Context) {
Context curCtx = (Context)ctx.getCtx();
traceContext = new DefaultTraceContext(curCtx);

// TODO do we need use isImport variable?
// isImport.set(true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ public void onEvent(MatricPackageEvent event, long sequence, boolean endOfBatch)
event.clear();
}

protected void send(byte[] data, int sendCount, String key) {
messageSender.send(data, sendCount);
}

private void flush(int sendCount, String key) throws IOException {
generator.flush();
if (baos != null && baos.size() > 0) {
Expand Down Expand Up @@ -355,9 +359,6 @@ private int write(PackageMetric packageMetric, int sendCount) throws IOException
return sendCount;
}

protected void send(byte[] data, int sendCount, String key) {
messageSender.send(data, sendCount);
}

}
}
8 changes: 8 additions & 0 deletions etrace-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM nimmis/java-centos:oracle-8-jdk as jdk8
EXPOSE 2890
ADD target/etrace-api.tar.gz /etrace-api/
WORKDIR /etrace-api
RUN tar -xf etrace-api.tar.gz
RUN ls

ENTRYPOINT ["sh","run.sh", "start"]
Loading

0 comments on commit 1ce8c02

Please sign in to comment.