Skip to content

Commit 024f4ed

Browse files
committed
Fix #32618: fix counter metrics for multiple replicas
1 parent 5f7eeb2 commit 024f4ed

12 files changed

Lines changed: 199 additions & 95 deletions

src/main/java/eu/openanalytics/containerproxy/event/BridgeableEvent.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
package eu.openanalytics.containerproxy.event;
2222

2323

24+
import com.fasterxml.jackson.annotation.JsonIgnore;
2425
import com.fasterxml.jackson.annotation.JsonTypeInfo;
26+
import lombok.With;
2527
import org.springframework.context.ApplicationEvent;
2628

2729
@JsonTypeInfo(
@@ -30,12 +32,25 @@
3032
)
3133
public abstract class BridgeableEvent extends ApplicationEvent {
3234

33-
public static final String SOURCE_NOT_AVAILABLE = "SOURCE_NOT_AVAILABLE";
35+
protected static final String SOURCE_NOT_AVAILABLE = "SOURCE_NOT_AVAILABLE";
3436

3537
public BridgeableEvent() {
3638
super(SOURCE_NOT_AVAILABLE);
3739
}
3840

41+
public BridgeableEvent(String source) {
42+
super(source);
43+
}
44+
3945
public abstract BridgeableEvent withSource(String source);
4046

47+
/**
48+
* Checks whether this event was produced by this replica/instance, i.e. it was not bridged.
49+
* @return whether this event was produced by this replica/instance.
50+
*/
51+
@JsonIgnore
52+
public boolean isLocalEvent() {
53+
return source.equals(SOURCE_NOT_AVAILABLE);
54+
}
55+
4156
}

src/main/java/eu/openanalytics/containerproxy/event/PendingProxyEvent.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,38 @@
2020
*/
2121
package eu.openanalytics.containerproxy.event;
2222

23+
import com.fasterxml.jackson.annotation.JsonCreator;
24+
import com.fasterxml.jackson.annotation.JsonProperty;
2325
import lombok.AccessLevel;
24-
import lombok.AllArgsConstructor;
2526
import lombok.EqualsAndHashCode;
2627
import lombok.NoArgsConstructor;
2728
import lombok.Value;
28-
import lombok.With;
2929

3030
@Value
3131
@EqualsAndHashCode(callSuper = true)
32-
@AllArgsConstructor
3332
@NoArgsConstructor(force = true, access = AccessLevel.PRIVATE) // Jackson deserialize compatibility
3433
public class PendingProxyEvent extends BridgeableEvent {
3534

36-
@With
37-
String source;
35+
String specId;
3836

3937
String proxyId;
4038

41-
String specId;
42-
43-
public PendingProxyEvent(String specId, String proxyId) {
44-
source = "SOURCE_NOT_AVAILABLE";
39+
@JsonCreator
40+
public PendingProxyEvent(@JsonProperty("source") String source,
41+
@JsonProperty("specId") String specId,
42+
@JsonProperty("proxyId") String proxyId) {
43+
super(source);
4544
this.specId = specId;
4645
this.proxyId = proxyId;
4746
}
4847

48+
public PendingProxyEvent(String specId, String proxyId) {
49+
this(SOURCE_NOT_AVAILABLE, specId, proxyId);
50+
}
51+
52+
@Override
53+
public PendingProxyEvent withSource(String source) {
54+
return new PendingProxyEvent(source, specId, proxyId);
55+
}
56+
4957
}

src/main/java/eu/openanalytics/containerproxy/event/ProxyPauseEvent.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,47 @@
2020
*/
2121
package eu.openanalytics.containerproxy.event;
2222

23+
import com.fasterxml.jackson.annotation.JsonCreator;
24+
import com.fasterxml.jackson.annotation.JsonProperty;
2325
import eu.openanalytics.containerproxy.model.runtime.Proxy;
2426
import lombok.AccessLevel;
25-
import lombok.AllArgsConstructor;
2627
import lombok.EqualsAndHashCode;
2728
import lombok.NoArgsConstructor;
2829
import lombok.Value;
29-
import lombok.With;
30+
import org.springframework.context.annotation.PropertySource;
3031

3132
import java.time.Duration;
3233

3334
@Value
3435
@EqualsAndHashCode(callSuper = true)
35-
@AllArgsConstructor
3636
@NoArgsConstructor(force = true, access = AccessLevel.PRIVATE) // Jackson deserialize compatibility
3737
public class ProxyPauseEvent extends BridgeableEvent {
3838

39-
@With
40-
String source;
41-
4239
String proxyId;
4340
String userId;
4441
String specId;
4542
Duration usageTime;
4643

44+
@JsonCreator
45+
public ProxyPauseEvent(@JsonProperty("source") String source,
46+
@JsonProperty("proxyId") String proxyId,
47+
@JsonProperty("userId") String userId,
48+
@JsonProperty("specId") String specId,
49+
@JsonProperty("usageTime") Duration usageTime) {
50+
super(source);
51+
this.proxyId = proxyId;
52+
this.userId = userId;
53+
this.specId = specId;
54+
this.usageTime = usageTime;
55+
}
56+
4757
public ProxyPauseEvent(Proxy proxy) {
48-
source = "SOURCE_NOT_AVAILABLE";
49-
proxyId = proxy.getId();
50-
userId = proxy.getUserId();
51-
specId = proxy.getSpecId();
52-
if (proxy.getStartupTimestamp() == 0) {
53-
usageTime = null;
54-
} else {
55-
usageTime = Duration.ofMillis(System.currentTimeMillis() - proxy.getStartupTimestamp());
56-
}
58+
this(SOURCE_NOT_AVAILABLE, proxy.getId(), proxy.getUserId(), proxy.getSpecId(),
59+
proxy.getStartupTimestamp() == 0 ? null : Duration.ofMillis(System.currentTimeMillis() - proxy.getStartupTimestamp()));
5760
}
5861

62+
@Override
63+
public ProxyPauseEvent withSource(String source) {
64+
return new ProxyPauseEvent(source, proxyId, userId, specId, usageTime);
65+
}
5966
}

src/main/java/eu/openanalytics/containerproxy/event/ProxyResumeEvent.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,41 @@
2020
*/
2121
package eu.openanalytics.containerproxy.event;
2222

23+
import com.fasterxml.jackson.annotation.JsonCreator;
24+
import com.fasterxml.jackson.annotation.JsonProperty;
2325
import eu.openanalytics.containerproxy.model.runtime.Proxy;
2426
import lombok.AccessLevel;
25-
import lombok.AllArgsConstructor;
2627
import lombok.EqualsAndHashCode;
2728
import lombok.NoArgsConstructor;
2829
import lombok.Value;
29-
import lombok.With;
3030

3131
@Value
3232
@EqualsAndHashCode(callSuper = true)
33-
@AllArgsConstructor
3433
@NoArgsConstructor(force = true, access = AccessLevel.PRIVATE) // Jackson deserialize compatibility
3534
public class ProxyResumeEvent extends BridgeableEvent {
3635

37-
@With
38-
String source;
39-
4036
String proxyId;
4137
String userId;
4238
String specId;
4339

40+
@JsonCreator
41+
public ProxyResumeEvent(@JsonProperty("source") String source,
42+
@JsonProperty("proxyId") String proxyId,
43+
@JsonProperty("userId") String userId,
44+
@JsonProperty("specId") String specId) {
45+
super(source);
46+
this.proxyId = proxyId;
47+
this.userId = userId;
48+
this.specId = specId;
49+
}
50+
4451
public ProxyResumeEvent(Proxy proxy) {
45-
source = "SOURCE_NOT_AVAILABLE";
46-
proxyId = proxy.getId();
47-
userId = proxy.getUserId();
48-
specId = proxy.getSpecId();
52+
this(SOURCE_NOT_AVAILABLE, proxy.getId(), proxy.getUserId(), proxy.getSpecId());
53+
}
54+
55+
@Override
56+
public ProxyResumeEvent withSource(String source) {
57+
return new ProxyResumeEvent(source, proxyId, userId, specId);
4958
}
5059

5160
}

src/main/java/eu/openanalytics/containerproxy/event/ProxyStartEvent.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,45 @@
2020
*/
2121
package eu.openanalytics.containerproxy.event;
2222

23+
import com.fasterxml.jackson.annotation.JsonCreator;
24+
import com.fasterxml.jackson.annotation.JsonProperty;
2325
import eu.openanalytics.containerproxy.model.runtime.Proxy;
2426
import eu.openanalytics.containerproxy.model.runtime.ProxyStartupLog;
2527
import lombok.AccessLevel;
26-
import lombok.AllArgsConstructor;
2728
import lombok.EqualsAndHashCode;
2829
import lombok.NoArgsConstructor;
2930
import lombok.Value;
30-
import lombok.With;
3131

3232
@Value
3333
@EqualsAndHashCode(callSuper = true)
34-
@AllArgsConstructor
3534
@NoArgsConstructor(force = true, access = AccessLevel.PRIVATE) // Jackson deserialize compatibility
3635
public class ProxyStartEvent extends BridgeableEvent {
3736

38-
@With
39-
String source;
40-
4137
String proxyId;
4238
String userId;
4339
String specId;
4440
ProxyStartupLog proxyStartupLog;
4541

46-
public ProxyStartEvent(Proxy proxy, ProxyStartupLog proxyStartupLog) {
47-
source = "SOURCE_NOT_AVAILABLE";
48-
proxyId = proxy.getId();
49-
userId = proxy.getUserId();
50-
specId = proxy.getSpecId();
42+
@JsonCreator
43+
public ProxyStartEvent(@JsonProperty("source") String source,
44+
@JsonProperty("proxyId") String proxyId,
45+
@JsonProperty("userId") String userId,
46+
@JsonProperty("specId") String specId,
47+
@JsonProperty("proxyStartupLog") ProxyStartupLog proxyStartupLog) {
48+
super(source);
49+
this.proxyId = proxyId;
50+
this.userId = userId;
51+
this.specId = specId;
5152
this.proxyStartupLog = proxyStartupLog;
5253
}
5354

55+
public ProxyStartEvent(Proxy proxy, ProxyStartupLog proxyStartupLog) {
56+
this(SOURCE_NOT_AVAILABLE, proxy.getId(), proxy.getUserId(), proxy.getSpecId(), proxyStartupLog);
57+
}
58+
59+
@Override
60+
public ProxyStartEvent withSource(String source) {
61+
return new ProxyStartEvent(source, proxyId, userId, specId, proxyStartupLog);
62+
}
63+
5464
}

src/main/java/eu/openanalytics/containerproxy/event/ProxyStartFailedEvent.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
package eu.openanalytics.containerproxy.event;
2222

2323

24+
import com.fasterxml.jackson.annotation.JsonCreator;
25+
import com.fasterxml.jackson.annotation.JsonProperty;
2426
import eu.openanalytics.containerproxy.model.runtime.Proxy;
2527
import lombok.AccessLevel;
2628
import lombok.AllArgsConstructor;
@@ -31,22 +33,30 @@
3133

3234
@Value
3335
@EqualsAndHashCode(callSuper = true)
34-
@AllArgsConstructor
3536
@NoArgsConstructor(force = true, access = AccessLevel.PRIVATE) // Jackson deserialize compatibility
3637
public class ProxyStartFailedEvent extends BridgeableEvent {
3738

38-
@With
39-
String source;
40-
4139
String proxyId;
4240
String userId;
4341
String specId;
4442

43+
@JsonCreator
44+
public ProxyStartFailedEvent(@JsonProperty("source") String source,
45+
@JsonProperty("proxyId") String proxyId,
46+
@JsonProperty("userId") String userId,
47+
@JsonProperty("specId") String specId) {
48+
super(source);
49+
this.proxyId = proxyId;
50+
this.userId = userId;
51+
this.specId = specId;
52+
}
53+
4554
public ProxyStartFailedEvent(Proxy proxy) {
46-
source = "SOURCE_NOT_AVAILABLE";
47-
proxyId = proxy.getId();
48-
userId = proxy.getUserId();
49-
specId = proxy.getSpecId();
55+
this(SOURCE_NOT_AVAILABLE, proxy.getId(), proxy.getUserId(), proxy.getSpecId());
5056
}
5157

58+
@Override
59+
public ProxyStartFailedEvent withSource(String source) {
60+
return new ProxyStartFailedEvent(source, proxyId, userId, specId);
61+
}
5262
}

src/main/java/eu/openanalytics/containerproxy/event/ProxyStopEvent.java

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,51 @@
2020
*/
2121
package eu.openanalytics.containerproxy.event;
2222

23+
import com.fasterxml.jackson.annotation.JsonCreator;
24+
import com.fasterxml.jackson.annotation.JsonProperty;
2325
import eu.openanalytics.containerproxy.model.runtime.Proxy;
2426
import eu.openanalytics.containerproxy.model.runtime.ProxyStopReason;
2527
import lombok.AccessLevel;
26-
import lombok.AllArgsConstructor;
2728
import lombok.EqualsAndHashCode;
2829
import lombok.NoArgsConstructor;
2930
import lombok.Value;
30-
import lombok.With;
3131

3232
import java.time.Duration;
3333

3434
@Value
3535
@EqualsAndHashCode(callSuper = true)
36-
@AllArgsConstructor
3736
@NoArgsConstructor(force = true, access = AccessLevel.PRIVATE) // Jackson deserialize compatibility
3837
public class ProxyStopEvent extends BridgeableEvent {
3938

40-
@With
41-
String source;
42-
4339
String proxyId;
4440
String userId;
4541
String specId;
4642
ProxyStopReason proxyStopReason;
4743
Duration usageTime;
4844

49-
public ProxyStopEvent(Proxy proxy, ProxyStopReason proxyStopReason) {
50-
source = "SOURCE_NOT_AVAILABLE";
51-
proxyId = proxy.getId();
52-
userId = proxy.getUserId();
53-
specId = proxy.getSpecId();
45+
@JsonCreator
46+
public ProxyStopEvent(@JsonProperty("source") String source,
47+
@JsonProperty("proxyId") String proxyId,
48+
@JsonProperty("userId") String userId,
49+
@JsonProperty("specId") String specId,
50+
@JsonProperty("proxyStopReason") ProxyStopReason proxyStopReason,
51+
@JsonProperty("usageTime") Duration usageTime) {
52+
super(source);
53+
this.proxyId = proxyId;
54+
this.userId = userId;
55+
this.specId = specId;
5456
this.proxyStopReason = proxyStopReason;
55-
if (proxy.getStartupTimestamp() == 0) {
56-
usageTime = null;
57-
} else {
58-
usageTime = Duration.ofMillis(System.currentTimeMillis() - proxy.getStartupTimestamp());
59-
}
57+
this.usageTime = usageTime;
58+
}
59+
60+
public ProxyStopEvent(Proxy proxy, ProxyStopReason proxyStopReason) {
61+
this(SOURCE_NOT_AVAILABLE, proxy.getId(), proxy.getUserId(), proxy.getSpecId(), proxyStopReason,
62+
proxy.getStartupTimestamp() == 0 ? null : Duration.ofMillis(System.currentTimeMillis() - proxy.getStartupTimestamp()));
63+
}
64+
65+
@Override
66+
public ProxyStopEvent withSource(String source) {
67+
return new ProxyStopEvent(source, proxyId, userId, specId, proxyStopReason, usageTime);
6068
}
6169

6270
}

0 commit comments

Comments
 (0)