Skip to content

Commit 28c343b

Browse files
authored
Merge pull request #5 from cisco-open/fix/static_analyis/issues
Fix test failures & issues identified from static analysis
2 parents cc40f95 + 634d337 commit 28c343b

File tree

11 files changed

+10
-12
lines changed

11 files changed

+10
-12
lines changed

src/main/java/io/opentelemetry/contrib/generator/core/EntityModelGenerator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ private void setParentToChildrenTypes(String parentType, Set<String> childTypes)
207207
entityModel.get(parentType).forEach(parentEntity -> parentEntity.setChildrenByType(new HashMap<>()));
208208
}
209209

210+
@SuppressWarnings("ArraysAsListWithZeroOrOneArgument")
210211
private void setParentToChildren(GeneratorEntity parent, String childrenType, int childStartIndex, int childEndIndex) {
211212
List<GeneratorEntity> children = entityModel.get(childrenType).subList(childStartIndex, childEndIndex);
212213
if (!parent.getChildrenByType().containsKey(childrenType) || parent.getChildrenByType().get(childrenType) == null) {
@@ -262,6 +263,7 @@ private int getEntityLevel(String entityType) {
262263
* @param parentType - Entity type of the parent from which to copy the attribute
263264
* @param attribute - Name/Key of the attribute to copy
264265
*/
266+
@SuppressWarnings("unused")
265267
public static void copyFromParent(String parentType, String attribute) {
266268
for (GeneratorEntity eachEntity: entityModel.get(EntityModelExpressions.expressionsGlobalKey.split(":")[1]).stream()
267269
.filter(entity -> entity.getParentsByType()!=null)
@@ -288,6 +290,7 @@ public static void copyFromParent(String parentType, String attribute) {
288290
* @param targetAttribute - Name of the attribute to be set in the current entity
289291
* @param suffixExpression - Expression to be evaluated for the suffix to the parent attribute value
290292
*/
293+
@SuppressWarnings("unused")
291294
public static void modifyFromParent(String parentType, String sourceAttribute, String targetAttribute, String suffixExpression) {
292295
for (GeneratorEntity eachEntity: entityModel.get(EntityModelExpressions.expressionsGlobalKey.split(":")[1])) {
293296
Optional<KeyValue> parentAttribute = eachEntity.getParentsByType().get(parentType).get(0)

src/main/java/io/opentelemetry/contrib/generator/core/jel/methods/EntityModelExpressions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* in a standalone context to process the expressions, all the implementing methods have to be public static.
3535
* @see ELProcessor
3636
*/
37+
@SuppressWarnings("unused")
3738
public class EntityModelExpressions {
3839

3940
private static final ConcurrentHashMap<String, Integer> counters = new ConcurrentHashMap<>();

src/main/java/io/opentelemetry/contrib/generator/telemetry/jel/methods/LogSeverityGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public static String severityDistributionCount(String requestID, String logName,
7070
* @param percentages corresponding list of percentages
7171
* @return severity
7272
*/
73+
@SuppressWarnings("unused")
7374
public static String severityDistributionPercentage(String requestID, String logName, List<String> severity, List<Long> percentages) {
7475
int totalPayloadCount = GeneratorsStateProvider.getLogGeneratorState(requestID).getGeneratorThreadMap()
7576
.get(logName).getLogDefinition().getPayloadCount();

src/main/java/io/opentelemetry/contrib/generator/telemetry/jel/methods/MELTAttributeGenerators.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* {@link io.opentelemetry.contrib.generator.core.jel.methods.EntityModelExpressions} will not work.
3737
* @see ELProcessor
3838
*/
39+
@SuppressWarnings("unused")
3940
public class MELTAttributeGenerators {
4041

4142
private static final ConcurrentHashMap<String, Integer> counters = new ConcurrentHashMap<>();

src/main/java/io/opentelemetry/contrib/generator/telemetry/jel/methods/MetricValueGenerators.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* in a standalone context to process the expressions, all the implementing methods have to be public static.
3333
* @see ELProcessor
3434
*/
35+
@SuppressWarnings("unused")
3536
public class MetricValueGenerators {
3637

3738
private static final ELProcessor jelProcessor = new ELProcessor();

src/main/java/io/opentelemetry/contrib/generator/telemetry/logs/LogMessageProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class LogMessageProvider {
3838
}
3939

4040
public static String getLogMessage(String severity) {
41-
List<String> possibleMessages = severityReasonsMap.entrySet().stream()
41+
@SuppressWarnings("OptionalGetWithoutIsPresent") List<String> possibleMessages = severityReasonsMap.entrySet().stream()
4242
.filter(severityMessages -> severityMessages.getKey().equalsIgnoreCase(severity))
4343
.findFirst().get().getValue();
4444
String plainMessage = possibleMessages.get(ThreadLocalRandom.current().nextInt(possibleMessages.size()));

src/main/java/io/opentelemetry/contrib/generator/telemetry/metrics/SummaryGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ private Summary getDoubleSummaryDataPoint(MetricDefinition metricDefinition) {
7171
private List<Object> getCountValues(MetricDefinition metricDefinition) {
7272
Object value = jelProcessor.eval(metricDefinition.getValueFunction());
7373
if (value instanceof List) {
74+
//noinspection unchecked
7475
return (List<Object>) value;
7576
}
7677
log.warn("Non summary variant used in valueFunction for summary metric '" + metricDefinition.getName() + "' " +

src/main/java/io/opentelemetry/contrib/generator/telemetry/traces/SpansGenerator.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,7 @@ private int getSpanStatusCode(int spanIndex) {
223223

224224
private ByteString[] getTraceIds(int count) {
225225
ByteString[] traceIds = new ByteString[count];
226-
IntStream.range(0, count).forEach(i -> {
227-
traceIds[i] = getId(true);
228-
});
226+
IntStream.range(0, count).forEach(i -> traceIds[i] = getId(true));
229227
return traceIds;
230228
}
231229

src/test/java/io/opentelemetry/contrib/generator/telemetry/TestAllGenerators.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ public void validatePacketCounts() {
7575
int metricPayloadCount = 10;
7676
int logsPayloadCount = 20;
7777
int expectedMetricPackets = METRIC_REPORTING_ENTITIES_COUNT * metricPayloadCount;
78-
//Add packets for aggregating, non-reporting entities
79-
expectedMetricPackets = expectedMetricPackets + 600;
8078
int expectedLogsPackets = LOG_REPORTING_ENTITIES_COUNT * logsPayloadCount;
8179
int expectedSpanPackets = 11518;
8280
Assert.assertEquals(testStore.getMetricsPacketCount(), expectedMetricPackets, "Mismatch in expected metric packets count");

src/test/java/io/opentelemetry/contrib/generator/telemetry/TestMetricsGenerator.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,9 @@ public void generateData() {
5959
public void testPayloadAndPacketCounts() {
6060
//Check payload count = payload count * each of 8 types of entities
6161
int payloadCount = 8 * PAYLOAD_COUNT;
62-
//Add payloads for aggregating, non-reporting entities
63-
payloadCount = payloadCount + 19;
6462
Assert.assertEquals(testStore.getMetricPayloads().size(), payloadCount, "Mismatch in payload count");
6563
//Check packet count = payload count * number of entities
6664
int expectedPacketCount = REPORTING_ENTITIES_COUNT * PAYLOAD_COUNT;
67-
expectedPacketCount = expectedPacketCount + 600;
6865
Assert.assertEquals(testStore.getMetricsPacketCount(), expectedPacketCount, "Mismatch in resource metrics packet count");
6966
//Check metric count for each metric = number of reporting entities * number of payloads
7067
}

0 commit comments

Comments
 (0)