Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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: 10 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

Requires Java 17

You will require an `application-local.yaml` file. It will look something like this:
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
Expand All @@ -19,6 +26,8 @@ cd ..
# 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
```

Expand Down
31 changes: 23 additions & 8 deletions src/main/kotlin/io/firetail/logging/core/FiretailBuffer.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package io.firetail.logging.core

import io.firetail.logging.core.FiretailLogger.Companion.LOGGER
import io.firetail.logging.servlet.FiretailMapper
import io.firetail.logging.spring.FiretailConfig
import org.slf4j.LoggerFactory
import java.util.*
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.TimeUnit
import java.util.concurrent.locks.ReentrantLock

class FiretailBuffer(
private val firetailConfig: FiretailConfig,
Expand All @@ -16,6 +18,7 @@ class FiretailBuffer(
private val buffer: MutableList<FiretailData> = mutableListOf()
private val scheduler: ScheduledExecutorService = Executors.newSingleThreadScheduledExecutor()
private val flushCallback = mutableListOf<FiretailData>()
private val bufferLock = ReentrantLock()

init {
// Schedule the periodic flush task
Expand All @@ -31,19 +34,31 @@ class FiretailBuffer(
)
}

// Caller sycronizes access before calling this function
fun add(item: FiretailData) {
buffer.add(item)
if (buffer.size >= firetailConfig.capacity) {
flush()
bufferLock.lock()
try {
buffer.add(item)
if (buffer.size >= firetailConfig.capacity) {
flush()
}
} finally {
bufferLock.unlock()
}
}

// Threadsafe - write and reset the cached data
fun flush(): String {
if (buffer.isNotEmpty()) {
LOGGER.debug("Buffer flushing ${buffer.size}")
val result = firetailTemplate.send(buffer.toList())
buffer.clear()
return firetailMapper.getResult(result)
bufferLock.lock()
try {
if (buffer.isNotEmpty()) {
LOGGER.debug("Buffer flushing ${buffer.size}")
val result = firetailTemplate.send(buffer)
buffer.clear()
return firetailMapper.getResult(result)
}
} finally {
bufferLock.unlock()
}
return ""
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/kotlin/io/firetail/logging/servlet/FiretailFilter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import io.firetail.logging.core.Constants.Companion.CORRELATION_ID
import io.firetail.logging.core.Constants.Companion.OP_NAME
import io.firetail.logging.core.Constants.Companion.REQUEST_ID
import io.firetail.logging.core.FiretailBuffer
import io.firetail.logging.spring.FiretailConfig
import io.firetail.logging.core.FiretailLogger
import io.firetail.logging.core.FiretailTemplate
import io.firetail.logging.spring.FiretailConfig
import io.firetail.logging.util.FiretailMDC
import jakarta.servlet.FilterChain
import jakarta.servlet.http.HttpServletRequest
Expand Down Expand Up @@ -75,9 +75,7 @@ class FiretailFilter(
)
CompletableFuture.runAsync {
try {
synchronized(firetailBuffer) {
firetailBuffer.add(firetailLog)
}
firetailBuffer.add(firetailLog)
} catch (e: Exception) {
LOGGER.error(e.message)
throw e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package io.firetail.logging

import io.firetail.logging.core.Constants
import io.firetail.logging.core.FiretailBuffer
import io.firetail.logging.spring.EnableFiretail
import io.firetail.logging.core.FiretailLogger
import io.firetail.logging.core.FiretailTemplate
import io.firetail.logging.servlet.FiretailFilter
import io.firetail.logging.servlet.FiretailHeaderInterceptor
import io.firetail.logging.servlet.FiretailMapper
import io.firetail.logging.spring.EnableFiretail
import io.firetail.logging.util.FiretailMDC
import io.firetail.logging.util.StringUtils
import org.assertj.core.api.Assertions.assertThat
Expand Down Expand Up @@ -37,6 +37,7 @@ import org.springframework.web.client.RestTemplate
@TestPropertySource(
properties = [
"firetail.url=http://localhost:\${wiremock.server.port}",
"firetail.buffer.capacity=5",
],
)
@EnableFiretail
Expand Down