diff --git a/changelog/v0.2.22.md b/changelog/v0.2.22.md
new file mode 100644
index 0000000..c33cb75
--- /dev/null
+++ b/changelog/v0.2.22.md
@@ -0,0 +1,10 @@
+# v0.2.22
+
+Fix IP observations freezing under steady traffic.
+
+## Fixed
+
+- The observation throttle updated its per-IP timestamp on every request, so an
+ address with traffic more often than once a minute never reached the write
+ window and its row stopped updating. The throttle now records a write at most
+ once a minute per address, regardless of request rate.
diff --git a/path-gateway/pom.xml b/path-gateway/pom.xml
index 1646d74..489c111 100644
--- a/path-gateway/pom.xml
+++ b/path-gateway/pom.xml
@@ -7,7 +7,7 @@
io.github.an1ndra
path-parent
- 0.2.21
+ 0.2.22
../pom.xml
diff --git a/path-gateway/src/main/java/com/anindra/path/gateway/IpAccessService.java b/path-gateway/src/main/java/com/anindra/path/gateway/IpAccessService.java
index ec5980a..1d7ac65 100644
--- a/path-gateway/src/main/java/com/anindra/path/gateway/IpAccessService.java
+++ b/path-gateway/src/main/java/com/anindra/path/gateway/IpAccessService.java
@@ -110,10 +110,11 @@ public void observe(String ip, String scope, String country, String userAgent) {
return;
}
long now = System.currentTimeMillis();
- Long previous = lastObserved.put(ip, now);
+ Long previous = lastObserved.get(ip);
if (previous != null && now - previous < OBSERVE_INTERVAL.toMillis()) {
return;
}
+ lastObserved.put(ip, now);
try {
IpObservation observation = observations.findById(ip).orElseGet(() -> {
IpObservation created = new IpObservation();
diff --git a/path-gateway/src/test/java/com/anindra/path/gateway/IpAccessServiceTest.java b/path-gateway/src/test/java/com/anindra/path/gateway/IpAccessServiceTest.java
index 7339253..d56dbba 100644
--- a/path-gateway/src/test/java/com/anindra/path/gateway/IpAccessServiceTest.java
+++ b/path-gateway/src/test/java/com/anindra/path/gateway/IpAccessServiceTest.java
@@ -98,6 +98,16 @@ void aPrefixOfZeroIsRejected() {
.isInstanceOf(ApiException.class);
}
+ @Test
+ void observationsAreThrottledByWritesNotByRequests() {
+ when(observations.findById("198.51.100.7")).thenReturn(java.util.Optional.empty());
+
+ service.observe("198.51.100.7", "api", "IN", "test");
+ service.observe("198.51.100.7", "api", "IN", "test");
+
+ Mockito.verify(observations, Mockito.times(1)).save(Mockito.any());
+ }
+
@Test
void createRejectsAnUnknownScopeOrAction() {
assertThatThrownBy(() -> service.createRule("10.0.0.0/8", "nope", "deny", null, null, "test"))
diff --git a/path-spring-ai/pom.xml b/path-spring-ai/pom.xml
index 19c6413..de659cb 100644
--- a/path-spring-ai/pom.xml
+++ b/path-spring-ai/pom.xml
@@ -7,7 +7,7 @@
io.github.an1ndra
path-parent
- 0.2.21
+ 0.2.22
../pom.xml
diff --git a/pom.xml b/pom.xml
index 794cabc..bb52ee6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,7 +13,7 @@
io.github.an1ndra
path-parent
- 0.2.21
+ 0.2.22
pom
path-parent
Build parent for Path, the provider-agnostic LLM gateway, and its Spring AI adapter