Skip to content

Commit 3a7436a

Browse files
authored
Merge pull request #2479 from telefonicaid/fix/channel_usage
Fix/channel usage
2 parents 2ab83e1 + 966e3ce commit 3a7436a

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

CHANGES_NEXT_RELEASE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
- [cygnus-ngsi] Fix log about channel usage when no CygnusChannel type is used (bug introduced in 3.17.0) (#2478)

cygnus-common/src/main/java/com/telefonica/iot/cygnus/channels/CygnusFileChannel.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,11 @@ public void setNumTakesFail(long n) {
120120
public double getUsage() {
121121
long currentSize = channelCounterRef.getChannelSize();
122122
long maxCapacity = channelCounterRef.getChannelCapacity();
123-
double usagePercentage = (double) currentSize / maxCapacity * 100;
124-
return usagePercentage;
123+
if (currentSize < 0 || maxCapacity <= 0) {
124+
return 0.0;
125+
}
126+
127+
return (currentSize * 100.0) / maxCapacity;
125128
} // getUsage
126129

127130
} // CygnusFileChannel

cygnus-common/src/main/java/com/telefonica/iot/cygnus/channels/CygnusMemoryChannel.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,11 @@ public void setNumTakesFail(long n) {
124124
public double getUsage() {
125125
long currentSize = channelCounterRef.getChannelSize();
126126
long maxCapacity = channelCounterRef.getChannelCapacity();
127-
double usagePercentage = (double) currentSize / maxCapacity * 100;
128-
return usagePercentage;
127+
if (currentSize < 0 || maxCapacity <= 0) {
128+
return 0.0;
129+
}
130+
131+
return (currentSize * 100.0) / maxCapacity;
129132
} // getUsage
130133

131134
} // CygnusMemoryChannel

cygnus-ngsi/src/main/java/com/telefonica/iot/cygnus/sinks/NGSISink.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,17 @@ private Status processNewBatches() {
514514
try {
515515
txn.begin();
516516

517-
CygnusChannel cygnusch = (CygnusChannel) ch;
518-
channelUsage = cygnusch.getUsage();
519-
LOGGER.debug("Channel usage: " + channelUsage + "% in sink " + this.getName());
520-
if (channelUsage > NGSIConstants.HIGH_CHANNEL_PERCENT_USAGE) {
521-
LOGGER.warn("High Channel usage: " + channelUsage + "% in sink " + this.getName());
517+
if (ch instanceof CygnusChannel) {
518+
CygnusChannel cygnusch = (CygnusChannel) ch;
519+
channelUsage = cygnusch.getUsage();
520+
521+
LOGGER.debug("Channel usage: " + channelUsage + "% in sink " + this.getName());
522+
if (channelUsage > NGSIConstants.HIGH_CHANNEL_PERCENT_USAGE) {
523+
LOGGER.warn("High Channel usage: " + channelUsage + "% in sink " + this.getName());
524+
}
525+
} else {
526+
// Flume channel "vanilla": do not get usage
527+
LOGGER.debug("Channel is not a CygnusChannel (" + ch.getClass().getName() + "). Skipping channel usage.");
522528
}
523529

524530
// Get and process as many events as the batch size

0 commit comments

Comments
 (0)