Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite Java code to Kotlin #4

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
90e7683
chore: Tidyup build issues
monowai Jul 25, 2023
cd5044f
refactor: Kotlin/Gradle
monowai Aug 3, 2023
b59950d
Merge pull request #2 from monowai/dev-refactor
muhammadn Aug 24, 2023
c158fe5
refactor: Simplify classes and introduce clearer defaults
monowai Sep 8, 2023
8fe24f5
feat: Beef up Interceptor tests
monowai Sep 9, 2023
414bee1
Merge branch 'muhammadn:main' into dev-refactor
monowai Sep 12, 2023
b1b0dc5
Merge pull request #3 from monowai/dev-refactor
muhammadn Oct 19, 2023
deddc9b
Merge branch 'main' of github.com:FireTail-io/firetail-java-lib
muhammadn Oct 19, 2023
55d1336
chore: Fix publishToMavenLocal
monowai Oct 24, 2023
a9ba96f
feat: Added Spring Boot Web Demo
monowai Oct 25, 2023
8e1abf8
feat: Added Open API documentation
monowai Oct 31, 2023
56a0a59
feat: Firetail Interceptor. Add tests to support correct disabling
monowai Nov 23, 2023
efabcac
feat: Serialization
monowai Nov 24, 2023
b35a62f
feat: Map payload
monowai Nov 27, 2023
ab40eaa
feat: Send logs
monowai Nov 28, 2023
b0e7ad8
feat: EnableFiretail annotation. remove config property
monowai Nov 29, 2023
aa49569
feat: Tidyup logging and duration
monowai Dec 1, 2023
cbaf27c
feat: Added a buffer for data logs. Minor package refactor
monowai Dec 4, 2023
87b1186
refactor: Internalise locking of the Buffer and remove the need to sy…
monowai Dec 5, 2023
bfd9baf
add issue notes and github actions
muhammadn Dec 5, 2023
69fe1c5
Merge branch 'feat/kotlin-migration' of github.com:FireTail-io/fireta…
muhammadn Dec 5, 2023
140ace4
change version for jdk
muhammadn Dec 5, 2023
d7a3737
check for multiple java versions
muhammadn Dec 5, 2023
1e956da
remove java 17
muhammadn Dec 5, 2023
a57ba9d
add back java-version
muhammadn Dec 5, 2023
24eaa35
cache builds
muhammadn Dec 5, 2023
238b878
add documentation
muhammadn Oct 7, 2024
e6a01ba
should be application-local.yml
muhammadn Oct 8, 2024
4566567
add a note to tell user about env vars
muhammadn Oct 15, 2024
d43259b
rephrase it a bit
muhammadn Oct 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Describe your changes

## Issue ticket number and link

## Checklist before requesting a review

- [ ] I have resolved any merge conflicts
- [ ] I have run tests locally and they pass
- [ ] I have linted and auto-formatted the code
- [ ] If there is new or changed functionality, I have added/updated the tests
- [ ] If there is new or changed functionality, I have added/updated the documentation
39 changes: 39 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Main

on: [push]

jobs:
test:
runs-on: ubuntu-latest

# https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix
strategy:
fail-fast: false
matrix:
# Uncomment ci_node_total and ci_node_index, ONLY if we have multiple tests
# and need to run it in parallel
# [n] - where the n is a number of parallel jobs you want to run your tests on.
# Use a higher number if you have slow tests to split them between more parallel jobs.
# Remember to update the value of the `ci_node_index` below to (0..n-1).
#ci_node_total: [8]
# Indexes for parallel jobs (starting from zero).
# E.g. use [0, 1] for 2 parallel jobs, [0, 1, 2] for 3 parallel jobs, etc.
#ci_node_index: [0, 1, 2, 3, 4, 5, 6, 7]
java-version: ['11', '17', '21']

env:
TZ: "Europe/Ireland"

steps:
- uses: actions/checkout@v2

- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'oracle'
cache: 'gradle'

- name: Run tests
run: |
./gradlew test
104 changes: 104 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# General
*.log
*.keystore
.history/
*.tgz

# git-secret rules
.secrets/*.*
!.secrets/*.secret
!.secrets/public-keys/
.gitsecret/keys/random_seed
.gitsecret/keys/pubring.kbx~
gradle.properties

.ci/gradle*

# You can put a script which call `yarn prettier-eslint --write` that prettify the file in-place.
# Keep in mind the hook files are executed by alphabet sequence: so `in_place_prettier_eslint` will be executed before `prettier_eslint`
buildtools/hooks/pre-commit.d/in_place_prettier_eslint

# Archives / Binaries
*.jar
*.zip
*.tar.gz
*.so
*.xcarchive

# MacOS
.DS_Store

# Build Output
build/
out/
bin/
codemr/

# JetBrains
.idea/
*.iml
*.ipr
*.iws
.mvn/
.project

# VSCode
.vscode/
*.code-workspace

# Eclipse
.settings/
.classpath

# Java
*.hprof
.gradle/
!gradle-wrapper.jar
!gradle-wrapper.properties


# Node or NPM or Yarn
npm-debug.log*
yarn-debug.log*
yarn-error.log*
node_modules/
.eslintcache

# Jest/Bamboo test results output
jest.json
coverage/

# Vagrant
.vagrant/

# Xcode
#
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace
**/*.framework/


# VIM
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]
version.yml

#Andorid
local.properties
/examples/src/main/resources/application-local.yml
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
# firetail-java-lib

## Building the library

1. In the projects root folder, run `./gradlew build -x test`
2. Run `./gradlew publishToMavenLocal`

### Springboot configuration
1. In `build.gradle.kts` (if you are using kotlin configuration), add within `dependencies {}`, the firetail library:

```
dependencies {
implementation("com.github.firetail-io:firetail-java-lib:$version")
}
```
2. Also in `build.gradle.kts` add below the `plugins {}`:

```
group = "com.github.firetail-io"
version = "0.0.1-SNAPSHOT"
```

3. In your springboot project, add `application-local.yml` in `build/resources`

**NOTE: Ensure there is no FIRETAIL_URL and FIRETAIL_API_KEY variable in your environment,**
**which will override your yaml file configuration**

```yaml
firetail:
apikey: "PS-02....441b09761c3"
url: "https://your-apiapi.logging.eu-north-west-99.sandbox.firetail.app"
## Cache control before dispatching logs to API
buffer:
# Millis
interval: 100000
# Max capacity
capacity: 5
```
89 changes: 89 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
plugins {
`java-library`
// application
`maven-publish`
signing
// Not possible to set the version for a plugin from a variable.
kotlin("plugin.spring") version "1.8.21"
kotlin("jvm") version "1.8.21"
id("io.spring.dependency-management") version "1.1.2"
}

buildscript {
val kotlinVersion = "1.8.21"
dependencies {
classpath("org.jetbrains.kotlin:kotlin-noarg:$kotlinVersion")
classpath("org.jmailen.gradle:kotlinter-gradle:3.14.0")
}
}

repositories {
mavenLocal()
maven {
url = uri("https://repo.maven.apache.org/maven2/")
}
mavenCentral()
}

group = "com.github.firetail-io"
version = "0.0.1-SNAPSHOT"
description = "firetail-java-lib"

// java.sourceCompatibility = JavaVersion.VERSION_1_8

dependencies {
// Dependencies are transitively imported from spring-boot-dependencies
implementation(
platform("org.springframework.boot:spring-boot-dependencies:3.1.5"),
)
implementation("org.jetbrains.kotlin:kotlin-stdlib")
api("com.fasterxml.jackson.module:jackson-module-kotlin")
api("org.slf4j:slf4j-api")
api("ch.qos.logback:logback-classic")
compileOnly("org.yaml:snakeyaml:2.2")
compileOnly("org.springframework.boot:spring-boot-autoconfigure")
compileOnly("org.springframework:spring-context")
compileOnly("org.springframework:spring-web")
compileOnly("org.springframework:spring-webmvc")
testImplementation(kotlin("test"))
testImplementation("org.springframework.boot:spring-boot-starter-test")
// javax vs. jakarta - Spring boot 3x uses jakarta. Need a version of this for < 3x for
// older SB apps
compileOnly("jakarta.annotation:jakarta.annotation-api")
compileOnly("jakarta.servlet:jakarta.servlet-api:5.0.0")
testImplementation("org.springframework.cloud:spring-cloud-contract-wiremock:4.0.4")
testImplementation("jakarta.servlet:jakarta.servlet-api")
// end javax vs. jakarta
testImplementation("org.springframework:spring-webmvc")
testImplementation("org.assertj:assertj-core")
testImplementation("org.mockito.kotlin:mockito-kotlin:5.0.0")
}

signing {
setRequired {
// signing is only required if the artifacts are to be published
gradle.taskGraph.allTasks.any { it is PublishToMavenRepository }
}
if (project.hasProperty("signJar") && project.property("signJar") == "true") {
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
sign(configurations["archives"])
}
}

publishing {
publications {
create<MavenPublication>("jar") {
artifact(tasks.named("jar"))
}
}
}

kotlin {
jvmToolchain(17)
}

tasks.test { // See 5️⃣
useJUnitPlatform() // JUnitPlatform for tests. See 6️⃣
}
33 changes: 33 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
41 changes: 41 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## Spring Boot Demo

Requires Java 17

You will require an `application-local.yml` file. It will look something like this:

```yaml
firetail:
apikey: "PS-02....441b09761c3"
url: "https://your-apiapi.logging.eu-north-west-99.sandbox.firetail.app"
## Cache control before dispatching logs to API
buffer:
# Millis
interval: 100000
# Max capacity
capacity: 5

```

Firstly, build the Firetail-Java-Library

```bash
# Build the firetail library
cd ..
./gradlew build publishToMavenLocal
# Run the example
cd examples
./gradlew bootRun
# By default, you'll want to hit this endpoint 5 times before the logs are dispatched
# Otherwise hit it < 5 and wait for 10 seconds
curl http://localhost:8080/hello
```

You can then login to the [FireTail app](https://www.sandbox.firetail.app/) and see your logs

## Open API documentation

This example uses OpenAPI v3

1. http://localhost:8080/api-docs
2. http://localhost:8080/swagger-ui.html
31 changes: 31 additions & 0 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
plugins {
id("org.springframework.boot") version "3.1.3"
id("io.spring.dependency-management") version "1.1.2"
kotlin("jvm") version "1.6.10"
}

group = "com.github.firetail-io"
version = "0.0.1-SNAPSHOT"

repositories {
mavenLocal()
maven {
url = uri("https://repo.maven.apache.org/maven2/")
}
mavenCentral()
}

dependencies {
implementation(
platform("org.springframework.boot:spring-boot-dependencies:3.1.5"),
)
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0")
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.github.firetail-io:firetail-java-lib:$version")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}

tasks.named<org.springframework.boot.gradle.tasks.run.BootRun>("bootRun") {
args("--spring.profiles.active=local")
}
Binary file added examples/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Loading
Loading