Skip to content

Commit e33b238

Browse files
authored
Add caching, tracing, logging, and batching to the plugin (#413)
1 parent 9df3422 commit e33b238

File tree

11 files changed

+1344
-766
lines changed

11 files changed

+1344
-766
lines changed

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM jenkins/jenkins:lts-jdk17
2+
3+
# install the plugin from update center to get all dependencies
4+
RUN jenkins-plugin-cli --plugins junit-sql-storage configuration-as-code database-postgresql opentelemetry
5+
# override with locally built version
6+
COPY target/junit-sql-storage.hpi /usr/share/jenkins/ref/plugins/junit-sql-storage.jpi
7+
8+
# configuration as code config for configuring this plugin
9+
COPY jenkins-config.yaml /usr/share/jenkins/ref/jenkins.yaml

README.md

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,48 @@ Tables will be automatically created.
2222

2323
## Getting started
2424

25-
Install your database vendor specific plugin, you can use the Jenkins plugin site to search for it:
25+
To install the plugin login to Jenkins → Manage Jenkins → Manage Plugins → Available → Search for 'JUnit SQL Storage' → Install.
2626

27-
https://plugins.jenkins.io/ui/search/?labels=database
27+
Use the following steps if you want to build and install the plugin from source.
28+
29+
### Building
30+
31+
To build the plugin use the `package` goal
32+
```
33+
$ mvn clean package -P quick-build
34+
```
35+
to run the tests use the `test` goal
36+
```
37+
$ mvn clean test
38+
```
39+
40+
### Deploying Jenkins and the plugin
2841

29-
e.g. you could install the [PostgreSQL Database](https://plugins.jenkins.io/database-postgresql/) plugin.
42+
To try out your changes you can deploy Jenkins using the `deploy.sh` file provided in the repository.
43+
```
44+
$ ./deploy.sh
45+
```
46+
This will compile the junit-sql-storage plugin (.hpi file), build a docker image of Jenkins with the compiled
47+
junit-sql-storage plugin installed, then deploy the docker swarm of jaeger, postgresql, and Jenkins.
3048

3149
### UI
3250

51+
You can also use the Jenkins UI to install the plugin and configure it.
52+
53+
### Installing Compiled Plugin
54+
55+
Once you've compiled the plugin (see above) you can install it from the Jenkins UI. Go to 'Manage Jenkins' → 'Plugins'
56+
→ 'Advanced' → 'Deploy' → 'Choose File' → 'Deploy'
57+
58+
<img alt="Install hpi plugin file" src="images/install-junit-sql-storage-plugin.png" width="800">
59+
60+
Next, install your database vendor specific plugin, you can use the Jenkins plugin site to search for it:
61+
62+
https://plugins.jenkins.io/ui/search/?labels=database
63+
64+
e.g. you could install the [PostgreSQL Database](https://plugins.jenkins.io/database-postgresql/) plugin or the
65+
[MySQL Database](https://plugins.jenkins.io/database-mysql/) plugin.
66+
3367
Manage Jenkins → Configure System → Junit
3468

3569
In the dropdown select 'SQL Database'
@@ -42,10 +76,15 @@ Select the database implementation you want to use and click 'Test Connection' t
4276

4377
![JUnit SQL plugin database configuration](images/junit-sql-database-config.png)
4478

79+
> **Note:** use `db` as the 'Host Name' if running Jenkins from inside a docker container as part of the
80+
> docker-compose.yaml deployment
81+
4582
Click 'Save'
4683

4784
### Configuration as code
4885

86+
You can also configure the plugin using the [Configuration as Code](https://plugins.jenkins.io/configuration-as-code/) plugin.
87+
4988
```yaml
5089
unclassified:
5190
globalDatabaseConfiguration:
@@ -60,6 +99,38 @@ unclassified:
6099
storage: "database"
61100
```
62101
102+
Here's an example of how to use it
103+
104+
```
105+
java -jar java-cli.jar -s http://<host.domain.name>:8080 -auth admin:<api_token> apply-configuration < junit-sql-storage-plugin-config.yml
106+
```
107+
108+
### Accessing Jaeger
109+
110+
You can access the Jaeger UI by going to `http://localhost:16686`, here you can view the performance of the Jenkins
111+
server and your plugin changes.
112+
113+
### Accessing the database
114+
115+
You can also query the postgres database by connecting to the `db` container.
116+
117+
```
118+
$ docker compose exec db psql -U postgres
119+
psql (16.3 (Debian 16.3-1.pgdg120+1))
120+
Type "help" for help.
121+
122+
postgres=# SELECT * FROM caseResults LIMIT 2;
123+
job | build | suite | package | classname | testname | errordetails | skipped | duration | stdout | stderr | st
124+
acktrace | timestamp
125+
------------+-------+------------------------------------------------------------+-------------------------------------------+------------------------------------------------------------+--------------------------+--------------+---------+----------+--------+--------+---
126+
---------+----------------------------
127+
xxxx-xxxxx | 1 | xxx.xxxx.xxx.xxxx.xxxxxx.xxxxxxxxxxxxxxxxxxxxxxxx | xxx.xxxx.xxx.xxxx.xxxxxx | xxx.xxxx.xxx.xxxx.xxxxxx.xxxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxxxxxxxxxxxxxxx | | | 0.331 | | |
128+
| 2024-06-13 18:18:26.897532
129+
xxxx-xxxxx | 1 | xxx.xxxx.xxx.xxxxxxxxx.xxxxxxx.xxxxxxxxxx.xxxxxxxxxxxxxxxx | xxx.xxxx.xxx.xxxxxxxxx.xxxxxxx.xxxxxxxxxx | xxx.xxxx.xxx.xxxxxxxxx.xxxxxxx.xxxxxxxxxx.xxxxxxxxxxxxxxxx | xxxxxxxxxxxxxxxxxx | | | 0.292 | | |
130+
| 2024-06-13 18:18:26.897532
131+
(2 rows)
132+
```
133+
63134
## Contributing
64135

65136
Refer to our [contribution guidelines](https://github.com/jenkinsci/.github/blob/master/CONTRIBUTING.md)

deploy.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
LightGreen='\033[1;32m'
4+
Red='\033[0;31m'
5+
White='\033[97m'
6+
NC='\033[0m'
7+
8+
echo "Building the Jenkins plugin..."
9+
echo -e "${LightGreen}mvn ${White}clean package -P quick-build${NC}"
10+
hpi_file="./target/junit-sql-storage.hpi"
11+
if ! mvn clean package -P quick-build || [ ! -e "$hpi_file" ]; then
12+
echo
13+
echo -e "${Red}Failed to build file ${NC}$hpi_file${Red} check the maven output${NC}"
14+
exit 1
15+
fi
16+
echo
17+
echo -e "${LightGreen}docker compose up --build -d${NC}"
18+
docker compose up --build -d
19+
echo
20+
# Monitor the Jenkins logs
21+
echo -e "${LightGreen}docker compose logs -f jenkins${NC}"
22+
docker compose logs -f jenkins

docker-compose.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,24 @@ services:
88
POSTGRES_PASSWORD: postgres
99
ports:
1010
- 5432:5432
11+
12+
jaeger:
13+
image: jaegertracing/all-in-one:1.57
14+
ports:
15+
- "4317:4317"
16+
- "16686:16686"
17+
18+
jenkins:
19+
build:
20+
context: .
21+
ports:
22+
- "8080:8080"
23+
- "50000:50000"
24+
- "5005:5005"
25+
environment:
26+
OTEL_EXPORTER_OTLP_ENDPOINT: http://jaeger:4317
27+
OTEL_SERVICE_NAME: jenkins
28+
OTEL_METRICS_EXPORTER: none
29+
OTEL_LOGS_EXPORTER: none
30+
OTEL_JAVAAGENT_LOGGING: simple
31+
JAVA_OPTS: "-Djenkins.install.runSetupWizard=false -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
51.1 KB
Loading
-4.43 KB
Loading

jenkins-config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
unclassified:
2+
globalDatabaseConfiguration:
3+
database:
4+
postgreSQL:
5+
database: postgres
6+
hostname: db
7+
password: postgres
8+
username: postgres
9+
validationQuery: "SELECT 1"
10+
junitTestResultStorage:
11+
storage: "database"
12+
openTelemetry:
13+
authentication: "noAuthentication"
14+
disabledResourceProviders: "io.opentelemetry.instrumentation.resources.ProcessResourceProvider"
15+
endpoint: "http://jaeger:4317"
16+
exportOtelConfigurationAsEnvironmentVariables: false
17+
ignoredSteps: "dir,echo,isUnix,pwd,properties"
18+
observabilityBackends:
19+
- jaeger:
20+
jaegerBaseUrl: "http://localhost:16686/"
21+
serviceName: "jenkins"
22+
serviceNamespace: "jenkins"

pom.xml

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44
<parent>
55
<groupId>org.jenkins-ci.plugins</groupId>
@@ -19,7 +19,6 @@
1919
</properties>
2020
<name>Junit SQL Storage Plugin</name>
2121
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
22-
2322
<dependencyManagement>
2423
<dependencies>
2524
<dependency>
@@ -29,18 +28,8 @@
2928
<scope>import</scope>
3029
<type>pom</type>
3130
</dependency>
32-
<dependency>
33-
<groupId>com.google.errorprone</groupId>
34-
<artifactId>error_prone_annotations</artifactId>
35-
<version>2.28.0</version>
36-
</dependency>
37-
<dependency>
38-
<groupId>io.jenkins.plugins</groupId>
39-
<artifactId>commons-lang3-api</artifactId>
40-
</dependency>
4131
</dependencies>
4232
</dependencyManagement>
43-
4433
<dependencies>
4534
<dependency>
4635
<groupId>org.jenkins-ci.plugins</groupId>
@@ -59,6 +48,21 @@
5948
<groupId>org.jenkins-ci.plugins</groupId>
6049
<artifactId>junit</artifactId>
6150
</dependency>
51+
<dependency>
52+
<groupId>io.jenkins.plugins</groupId>
53+
<artifactId>caffeine-api</artifactId>
54+
</dependency>
55+
<dependency>
56+
<groupId>io.jenkins.plugins</groupId>
57+
<artifactId>opentelemetry</artifactId>
58+
<version>3.1215.vc9db_a_0b_34c2a_</version>
59+
<exclusions>
60+
<exclusion>
61+
<groupId>com.google.errorprone</groupId>
62+
<artifactId>error_prone_annotations</artifactId>
63+
</exclusion>
64+
</exclusions>
65+
</dependency>
6266
<dependency>
6367
<groupId>org.jenkins-ci.plugins.workflow</groupId>
6468
<artifactId>workflow-basic-steps</artifactId>
@@ -109,22 +113,24 @@
109113
</exclusion>
110114
</exclusions>
111115
</dependency>
116+
<dependency>
117+
<groupId>org.mockito</groupId>
118+
<artifactId>mockito-core</artifactId>
119+
<scope>test</scope>
120+
</dependency>
112121
</dependencies>
113-
114122
<licenses>
115123
<license>
116124
<name>MIT License</name>
117125
<url>https://opensource.org/licenses/MIT</url>
118126
</license>
119127
</licenses>
120-
121128
<scm>
122129
<connection>scm:git:https://github.com/${gitHubRepo}</connection>
123130
<developerConnection>scm:git:https://github.com/${gitHubRepo}</developerConnection>
124131
<url>https://github.com/${gitHubRepo}</url>
125132
<tag>${scmTag}</tag>
126133
</scm>
127-
128134
<repositories>
129135
<repository>
130136
<id>repo.jenkins-ci.org</id>

0 commit comments

Comments
 (0)