Skip to content

Commit

Permalink
Add caching, tracing, logging, and batching to the plugin (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtmoore authored Jun 15, 2024
1 parent 9df3422 commit e33b238
Show file tree
Hide file tree
Showing 11 changed files with 1,344 additions and 766 deletions.
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM jenkins/jenkins:lts-jdk17

# install the plugin from update center to get all dependencies
RUN jenkins-plugin-cli --plugins junit-sql-storage configuration-as-code database-postgresql opentelemetry
# override with locally built version
COPY target/junit-sql-storage.hpi /usr/share/jenkins/ref/plugins/junit-sql-storage.jpi

# configuration as code config for configuring this plugin
COPY jenkins-config.yaml /usr/share/jenkins/ref/jenkins.yaml
77 changes: 74 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,48 @@ Tables will be automatically created.

## Getting started

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

https://plugins.jenkins.io/ui/search/?labels=database
Use the following steps if you want to build and install the plugin from source.

### Building

To build the plugin use the `package` goal
```
$ mvn clean package -P quick-build
```
to run the tests use the `test` goal
```
$ mvn clean test
```

### Deploying Jenkins and the plugin

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

### UI

You can also use the Jenkins UI to install the plugin and configure it.

### Installing Compiled Plugin

Once you've compiled the plugin (see above) you can install it from the Jenkins UI. Go to 'Manage Jenkins' → 'Plugins'
→ 'Advanced' → 'Deploy' → 'Choose File' → 'Deploy'

<img alt="Install hpi plugin file" src="images/install-junit-sql-storage-plugin.png" width="800">

Next, install your database vendor specific plugin, you can use the Jenkins plugin site to search for it:

https://plugins.jenkins.io/ui/search/?labels=database

e.g. you could install the [PostgreSQL Database](https://plugins.jenkins.io/database-postgresql/) plugin or the
[MySQL Database](https://plugins.jenkins.io/database-mysql/) plugin.

Manage Jenkins → Configure System → Junit

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

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

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

### Configuration as code

You can also configure the plugin using the [Configuration as Code](https://plugins.jenkins.io/configuration-as-code/) plugin.

```yaml
unclassified:
globalDatabaseConfiguration:
Expand All @@ -60,6 +99,38 @@ unclassified:
storage: "database"
```
Here's an example of how to use it
```
java -jar java-cli.jar -s http://<host.domain.name>:8080 -auth admin:<api_token> apply-configuration < junit-sql-storage-plugin-config.yml
```

### Accessing Jaeger

You can access the Jaeger UI by going to `http://localhost:16686`, here you can view the performance of the Jenkins
server and your plugin changes.

### Accessing the database

You can also query the postgres database by connecting to the `db` container.

```
$ docker compose exec db psql -U postgres
psql (16.3 (Debian 16.3-1.pgdg120+1))
Type "help" for help.
postgres=# SELECT * FROM caseResults LIMIT 2;
job | build | suite | package | classname | testname | errordetails | skipped | duration | stdout | stderr | st
acktrace | timestamp
------------+-------+------------------------------------------------------------+-------------------------------------------+------------------------------------------------------------+--------------------------+--------------+---------+----------+--------+--------+---
---------+----------------------------
xxxx-xxxxx | 1 | xxx.xxxx.xxx.xxxx.xxxxxx.xxxxxxxxxxxxxxxxxxxxxxxx | xxx.xxxx.xxx.xxxx.xxxxxx | xxx.xxxx.xxx.xxxx.xxxxxx.xxxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxxxxxxxxxxxxxxx | | | 0.331 | | |
| 2024-06-13 18:18:26.897532
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 | | |
| 2024-06-13 18:18:26.897532
(2 rows)
```

## Contributing

Refer to our [contribution guidelines](https://github.com/jenkinsci/.github/blob/master/CONTRIBUTING.md)
Expand Down
22 changes: 22 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

LightGreen='\033[1;32m'
Red='\033[0;31m'
White='\033[97m'
NC='\033[0m'

echo "Building the Jenkins plugin..."
echo -e "${LightGreen}mvn ${White}clean package -P quick-build${NC}"
hpi_file="./target/junit-sql-storage.hpi"
if ! mvn clean package -P quick-build || [ ! -e "$hpi_file" ]; then
echo
echo -e "${Red}Failed to build file ${NC}$hpi_file${Red} check the maven output${NC}"
exit 1
fi
echo
echo -e "${LightGreen}docker compose up --build -d${NC}"
docker compose up --build -d
echo
# Monitor the Jenkins logs
echo -e "${LightGreen}docker compose logs -f jenkins${NC}"
docker compose logs -f jenkins
21 changes: 21 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,24 @@ services:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432

jaeger:
image: jaegertracing/all-in-one:1.57
ports:
- "4317:4317"
- "16686:16686"

jenkins:
build:
context: .
ports:
- "8080:8080"
- "50000:50000"
- "5005:5005"
environment:
OTEL_EXPORTER_OTLP_ENDPOINT: http://jaeger:4317
OTEL_SERVICE_NAME: jenkins
OTEL_METRICS_EXPORTER: none
OTEL_LOGS_EXPORTER: none
OTEL_JAVAAGENT_LOGGING: simple
JAVA_OPTS: "-Djenkins.install.runSetupWizard=false -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
Binary file added images/install-junit-sql-storage-plugin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/junit-sql-database-config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions jenkins-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
unclassified:
globalDatabaseConfiguration:
database:
postgreSQL:
database: postgres
hostname: db
password: postgres
username: postgres
validationQuery: "SELECT 1"
junitTestResultStorage:
storage: "database"
openTelemetry:
authentication: "noAuthentication"
disabledResourceProviders: "io.opentelemetry.instrumentation.resources.ProcessResourceProvider"
endpoint: "http://jaeger:4317"
exportOtelConfigurationAsEnvironmentVariables: false
ignoredSteps: "dir,echo,isUnix,pwd,properties"
observabilityBackends:
- jaeger:
jaegerBaseUrl: "http://localhost:16686/"
serviceName: "jenkins"
serviceNamespace: "jenkins"
36 changes: 21 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -19,7 +19,6 @@
</properties>
<name>Junit SQL Storage Plugin</name>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>

<dependencyManagement>
<dependencies>
<dependency>
Expand All @@ -29,18 +28,8 @@
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
<version>2.28.0</version>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>commons-lang3-api</artifactId>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -59,6 +48,21 @@
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>caffeine-api</artifactId>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>opentelemetry</artifactId>
<version>3.1215.vc9db_a_0b_34c2a_</version>
<exclusions>
<exclusion>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
Expand Down Expand Up @@ -109,22 +113,24 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<licenses>
<license>
<name>MIT License</name>
<url>https://opensource.org/licenses/MIT</url>
</license>
</licenses>

<scm>
<connection>scm:git:https://github.com/${gitHubRepo}</connection>
<developerConnection>scm:git:https://github.com/${gitHubRepo}</developerConnection>
<url>https://github.com/${gitHubRepo}</url>
<tag>${scmTag}</tag>
</scm>

<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
Expand Down
Loading

0 comments on commit e33b238

Please sign in to comment.