Skip to content

Commit 5f89d21

Browse files
authored
Merge pull request #1304 from nats-io/api-stats-update
Update account ApiStats with level and inflight
2 parents e5b9bd6 + ee9a7a0 commit 5f89d21

File tree

5 files changed

+107
-38
lines changed

5 files changed

+107
-38
lines changed

src/main/java/io/nats/client/api/AccountTier.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,25 @@ public class AccountTier {
2626

2727
private final int memory;
2828
private final int storage;
29+
private final int reservedMemory;
30+
private final int reservedStorage;
2931
private final int streams;
3032
private final int consumers;
3133
private final AccountLimits limits;
3234

3335
AccountTier(JsonValue vAccountTier) {
3436
memory = readInteger(vAccountTier, MEMORY, 0);
3537
storage = readInteger(vAccountTier, STORAGE, 0);
38+
reservedMemory = readInteger(vAccountTier, RESERVED_MEMORY, 0);
39+
reservedStorage = readInteger(vAccountTier, RESERVED_STORAGE, 0);
3640
streams = readInteger(vAccountTier, STREAMS, 0);
3741
consumers = readInteger(vAccountTier, CONSUMERS, 0);
3842
limits = new AccountLimits(readObject(vAccountTier, LIMITS));
3943
}
4044

4145
/**
4246
* Memory Storage being used for Stream Message storage in this tier.
43-
* @return the storage in bytes
47+
* @return the memory storage in bytes
4448
*/
4549
public int getMemory() {
4650
return memory;
@@ -54,6 +58,22 @@ public int getStorage() {
5458
return storage;
5559
}
5660

61+
/**
62+
* Bytes that is reserved for memory usage by this account on the server
63+
* @return the memory usage in bytes
64+
*/
65+
public int getReservedMemory() {
66+
return reservedMemory;
67+
}
68+
69+
/**
70+
* Bytes that is reserved for disk usage by this account on the server
71+
* @return the disk usage in bytes
72+
*/
73+
public int getReservedStorage() {
74+
return reservedStorage;
75+
}
76+
5777
/**
5878
* Number of active streams in this tier.
5979
* @return the number of streams

src/main/java/io/nats/client/api/ApiStats.java

+39-8
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,66 @@
1616
import io.nats.client.support.JsonValue;
1717
import io.nats.client.support.JsonValueUtils;
1818

19-
import static io.nats.client.support.ApiConstants.ERRORS;
20-
import static io.nats.client.support.ApiConstants.TOTAL;
19+
import static io.nats.client.support.ApiConstants.*;
2120

2221
/**
2322
* Represents the JetStream Account Api Stats
2423
*/
2524
public class ApiStats {
2625

27-
private final int total;
28-
private final int errors;
26+
private final int level;
27+
private final long total;
28+
private final long errors;
29+
private final long inFlight;
2930

3031
ApiStats(JsonValue vApiStats) {
31-
this.total = JsonValueUtils.readInteger(vApiStats, TOTAL, 0);
32-
this.errors = JsonValueUtils.readInteger(vApiStats, ERRORS, 0);
32+
this.level = JsonValueUtils.readInteger(vApiStats, LEVEL, 0);
33+
this.total = JsonValueUtils.readLong(vApiStats, TOTAL, 0);
34+
this.errors = JsonValueUtils.readLong(vApiStats, ERRORS, 0);
35+
this.inFlight = JsonValueUtils.readLong(vApiStats, INFLIGHT, 0);
36+
}
37+
38+
public int getLevel() {
39+
return level;
3340
}
3441

3542
/**
3643
* Total number of API requests received for this account
3744
* @return the total requests
3845
*/
39-
public int getTotal() {
46+
public long getTotalApiRequests() {
4047
return total;
4148
}
4249

4350
/**
4451
* API requests that resulted in an error response
4552
* @return the error count
4653
*/
47-
public int getErrors() {
54+
public long getErrorCount() {
4855
return errors;
4956
}
57+
58+
public long getInFlight() {
59+
return inFlight;
60+
}
61+
62+
/**
63+
* @deprecated Deprecated, replaced with getTotalApiRequests
64+
* Total number of API requests received for this account
65+
* @return the total requests
66+
*/
67+
@Deprecated
68+
public int getTotal() {
69+
return (int)total;
70+
}
71+
72+
/**
73+
* @deprecated Deprecated, replaced with getErrorErroredRequests
74+
* API requests that resulted in an error response
75+
* @return the error count
76+
*/
77+
@Deprecated
78+
public int getErrors() {
79+
return (int)errors;
80+
}
5081
}

src/main/java/io/nats/client/support/ApiConstants.java

+4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public interface ApiConstants {
8787
String ID = "id";
8888
String IDLE_HEARTBEAT = "idle_heartbeat";
8989
String INACTIVE_THRESHOLD= "inactive_threshold";
90+
String INFLIGHT = "inflight";
9091
String INTERNAL = "internal";
9192
String JETSTREAM = "jetstream";
9293
String KEEP = "keep";
@@ -98,6 +99,7 @@ public interface ApiConstants {
9899
String LAST_SEQ = "last_seq";
99100
String LAST_TS = "last_ts";
100101
String LEADER = "leader";
102+
String LEVEL = "level";
101103
String LIMIT = "limit";
102104
String LIMITS = "limits";
103105
String LINK = "link";
@@ -171,6 +173,8 @@ public interface ApiConstants {
171173
String REPLICAS = "replicas";
172174
String REPUBLISH = "republish";
173175
String REQUEST = "request";
176+
String RESERVED_MEMORY = "reserved_memory";
177+
String RESERVED_STORAGE = "reserved_storage";
174178
String RESPONSE = "response";
175179
String RETENTION = "retention";
176180
String SAMPLE_FREQ = "sample_freq";

src/test/java/io/nats/client/api/AccountStatisticsTests.java

+34-28
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,16 @@ public void testAccountStatsImpl() {
3737
assertEquals("ngs", as.getDomain());
3838

3939
ApiStats api = as.getApi();
40-
assertEquals(301, api.getTotal());
41-
assertEquals(302, api.getErrors());
40+
assertEquals(301, api.getTotal()); // COVERAGE
41+
assertEquals(302, api.getErrors()); // COVERAGE
42+
assertEquals(301, api.getTotalApiRequests());
43+
assertEquals(302, api.getErrorCount());
44+
assertEquals(303, api.getLevel());
45+
assertEquals(304, api.getInFlight());
4246

4347
Map<String, AccountTier> tiers = as.getTiers();
44-
AccountTier tier = tiers.get("R1");
45-
assertNotNull(tier);
46-
assertEquals(401, tier.getMemory());
47-
assertEquals(402, tier.getStorage());
48-
assertEquals(403, tier.getStreams());
49-
assertEquals(404, tier.getConsumers());
50-
validateAccountLimits(tier.getLimits(), 500);
51-
52-
tier = tiers.get("R3");
53-
assertNotNull(tier);
54-
assertEquals(601, tier.getMemory());
55-
assertEquals(602, tier.getStorage());
56-
assertEquals(603, tier.getStreams());
57-
assertEquals(604, tier.getConsumers());
58-
validateAccountLimits(tier.getLimits(), 700);
48+
validateTier(tiers.get("R1"), 400, 500);
49+
validateTier(tiers.get("R3"), 600, 700);
5950

6051
assertNotNull(as.toString()); // COVERAGE
6152

@@ -66,7 +57,6 @@ public void testAccountStatsImpl() {
6657
assertEquals(0, as.getConsumers());
6758

6859
AccountLimits al = as.getLimits();
69-
assertNotNull(al);
7060
assertEquals(0, al.getMaxMemory());
7161
assertEquals(0, al.getMaxStorage());
7262
assertEquals(0, al.getMaxStreams());
@@ -78,18 +68,34 @@ public void testAccountStatsImpl() {
7868

7969
api = as.getApi();
8070
assertNotNull(api);
81-
assertEquals(0, api.getTotal());
82-
assertEquals(0, api.getErrors());
71+
assertEquals(0, api.getTotal()); // COVERAGE
72+
assertEquals(0, api.getErrors()); // COVERAGE
73+
assertEquals(0, api.getTotalApiRequests());
74+
assertEquals(0, api.getErrorCount());
75+
assertEquals(0, api.getLevel());
76+
assertEquals(0, api.getInFlight());
8377
}
8478

85-
private void validateAccountLimits(AccountLimits al, int id) {
86-
assertEquals(id + 1, al.getMaxMemory());
87-
assertEquals(id + 2, al.getMaxStorage());
88-
assertEquals(id + 3, al.getMaxStreams());
89-
assertEquals(id + 4, al.getMaxConsumers());
90-
assertEquals(id + 5, al.getMaxAckPending());
91-
assertEquals(id + 6, al.getMemoryMaxStreamBytes());
92-
assertEquals(id + 7, al.getStorageMaxStreamBytes());
79+
private void validateTier(AccountTier tier, int tierBase, int limitsIdBase) {
80+
assertNotNull(tier);
81+
assertEquals(tierBase + 1, tier.getMemory());
82+
assertEquals(tierBase + 2, tier.getStorage());
83+
assertEquals(tierBase + 3, tier.getStreams());
84+
assertEquals(tierBase + 4, tier.getConsumers());
85+
assertEquals(tierBase + 5, tier.getReservedMemory());
86+
assertEquals(tierBase + 6, tier.getReservedStorage());
87+
validateAccountLimits(tier.getLimits(), limitsIdBase);
88+
}
89+
90+
private static void validateAccountLimits(AccountLimits al, int limitsIdBase) {
91+
assertNotNull(al);
92+
assertEquals(limitsIdBase + 1, al.getMaxMemory());
93+
assertEquals(limitsIdBase + 2, al.getMaxStorage());
94+
assertEquals(limitsIdBase + 3, al.getMaxStreams());
95+
assertEquals(limitsIdBase + 4, al.getMaxConsumers());
96+
assertEquals(limitsIdBase + 5, al.getMaxAckPending());
97+
assertEquals(limitsIdBase + 6, al.getMemoryMaxStreamBytes());
98+
assertEquals(limitsIdBase + 7, al.getStorageMaxStreamBytes());
9399
assertTrue(al.isMaxBytesRequired());
94100
}
95101
}

src/test/resources/data/AccountStatistics.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"type": "io.nats.jetstream.api.v1.account_info_response",
33
"memory": 101,
44
"storage": 102,
5+
"reserved_memory": 105,
6+
"reserved_storage": 106,
57
"streams": 103,
68
"consumers": 104,
79
"limits": {
@@ -16,13 +18,17 @@
1618
},
1719
"domain": "ngs",
1820
"api": {
21+
"level": 303,
1922
"total": 301,
20-
"errors": 302
23+
"errors": 302,
24+
"inflight": 304
2125
},
2226
"tiers": {
2327
"R1": {
2428
"memory": 401,
2529
"storage": 402,
30+
"reserved_memory": 405,
31+
"reserved_storage": 406,
2632
"streams": 403,
2733
"consumers": 404,
2834
"limits": {
@@ -39,6 +45,8 @@
3945
"R3": {
4046
"memory": 601,
4147
"storage": 602,
48+
"reserved_memory": 605,
49+
"reserved_storage": 606,
4250
"streams": 603,
4351
"consumers": 604,
4452
"limits": {

0 commit comments

Comments
 (0)