Skip to content

Commit eed49c4

Browse files
committed
Convert more classes
1 parent 3d881b6 commit eed49c4

File tree

5 files changed

+80
-45
lines changed

5 files changed

+80
-45
lines changed

agent/agent-profiler/agent-diagnostics/src/main/java/com/microsoft/applicationinsights/diagnostics/collection/libos/hardware/MemoryInfo.java

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,64 @@
33

44
package com.microsoft.applicationinsights.diagnostics.collection.libos.hardware;
55

6-
import com.fasterxml.jackson.annotation.JsonCreator;
7-
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import com.azure.json.JsonSerializable;
7+
import com.azure.json.JsonWriter;
8+
import java.io.IOException;
89

9-
public class MemoryInfo {
10+
public class MemoryInfo implements JsonSerializable<MemoryInfo> {
1011

11-
private final long totalInKb;
12+
private long totalInKb;
1213

13-
private final long freeInKb;
14+
private long freeInKb;
1415

15-
private final long virtualMemoryTotalInKb;
16+
private long virtualMemoryTotalInKb;
1617

17-
private final long virtualMemoryUsedInKb;
18-
19-
@JsonCreator
20-
public MemoryInfo(
21-
@JsonProperty("totalInKB") long totalInKb,
22-
@JsonProperty("freeInKB") long freeInKb,
23-
@JsonProperty("virtualMemoryTotalInKB") long virtualMemoryTotalInKb,
24-
@JsonProperty("virtualMemoryUsedInKB") long virtualMemoryUsedInKb) {
25-
26-
this.totalInKb = totalInKb;
27-
this.freeInKb = freeInKb;
28-
this.virtualMemoryTotalInKb = virtualMemoryTotalInKb;
29-
this.virtualMemoryUsedInKb = virtualMemoryUsedInKb;
30-
}
18+
private long virtualMemoryUsedInKb;
3119

3220
public long getTotalInKb() {
3321
return totalInKb;
3422
}
3523

24+
public MemoryInfo setTotalInKb(long totalInKb) {
25+
this.totalInKb = totalInKb;
26+
return this;
27+
}
28+
3629
public long getFreeInKb() {
3730
return freeInKb;
3831
}
3932

33+
public MemoryInfo setFreeInKb(long freeInKb) {
34+
this.freeInKb = freeInKb;
35+
return this;
36+
}
37+
4038
public long getVirtualMemoryTotalInKb() {
4139
return virtualMemoryTotalInKb;
4240
}
4341

42+
public MemoryInfo setVirtualMemoryTotalInKb(long virtualMemoryTotalInKb) {
43+
this.virtualMemoryTotalInKb = virtualMemoryTotalInKb;
44+
return this;
45+
}
46+
4447
public long getVirtualMemoryUsedInKb() {
4548
return virtualMemoryUsedInKb;
4649
}
50+
51+
public MemoryInfo setVirtualMemoryUsedInKb(long virtualMemoryUsedInKb) {
52+
this.virtualMemoryUsedInKb = virtualMemoryUsedInKb;
53+
return this;
54+
}
55+
56+
@Override
57+
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
58+
jsonWriter.writeStartObject();
59+
jsonWriter.writeLongField("totalInKb", totalInKb);
60+
jsonWriter.writeLongField("freeInKb", freeInKb);
61+
jsonWriter.writeLongField("virtualMemoryTotalInKb", virtualMemoryTotalInKb);
62+
jsonWriter.writeLongField("virtualMemoryUsedInKb", virtualMemoryUsedInKb);
63+
jsonWriter.writeEndObject();
64+
return jsonWriter;
65+
}
4766
}

agent/agent-profiler/agent-diagnostics/src/main/java/com/microsoft/applicationinsights/diagnostics/collection/libos/os/linux/LinuxMemoryInfoReader.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ public class LinuxMemoryInfoReader extends TwoStepProcReader implements MemoryIn
1616
private int freeInKbIndex = -1;
1717
private int virtualMemoryTotalInKbIndex = -1;
1818
private int virtualMemoryUsedInKbIndex = -1;
19-
private MemoryInfo memoryInfo = new MemoryInfo(-1, -1, -1, -1);
19+
private MemoryInfo memoryInfo =
20+
new MemoryInfo()
21+
.setTotalInKb(-1)
22+
.setFreeInKb(-1)
23+
.setVirtualMemoryTotalInKb(-1)
24+
.setVirtualMemoryUsedInKb(-1);
2025

2126
public LinuxMemoryInfoReader() {
2227
super(new File(MEMINFO));
@@ -46,7 +51,11 @@ public MemoryInfo readMemoryInfo(String content) {
4651
long virtualMemoryTotalInKb = readMemoryNumber(lines[virtualMemoryTotalInKbIndex]);
4752
long virtualMemoryUsedInKb = readMemoryNumber(lines[virtualMemoryUsedInKbIndex]);
4853

49-
return new MemoryInfo(totalInKb, freeInKb, virtualMemoryTotalInKb, virtualMemoryUsedInKb);
54+
return new MemoryInfo()
55+
.setTotalInKb(totalInKb)
56+
.setFreeInKb(freeInKb)
57+
.setVirtualMemoryTotalInKb(virtualMemoryTotalInKb)
58+
.setVirtualMemoryUsedInKb(virtualMemoryUsedInKb);
5059
}
5160

5261
private static long readMemoryNumber(String line) {

agent/agent-profiler/agent-diagnostics/src/main/java/com/microsoft/applicationinsights/diagnostics/collection/libos/os/nop/NoOpMemoryInfoReader.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ public void update() throws OperatingSystemInteractionException {}
1717

1818
@Override
1919
public MemoryInfo getMemoryInfo() {
20-
return new MemoryInfo(-1, -1, -1, -1);
20+
return new MemoryInfo()
21+
.setTotalInKb(-1)
22+
.setFreeInKb(-1)
23+
.setVirtualMemoryTotalInKb(-1)
24+
.setVirtualMemoryUsedInKb(-1);
2125
}
2226

2327
@Override

agent/agent-profiler/agent-diagnostics/src/main/java/com/microsoft/applicationinsights/diagnostics/collection/libos/process/ProcessInfo.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,8 @@
33

44
package com.microsoft.applicationinsights.diagnostics.collection.libos.process;
55

6-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
7-
import com.fasterxml.jackson.annotation.JsonTypeInfo;
86
import java.util.Map;
97

10-
@JsonTypeInfo(
11-
use = JsonTypeInfo.Id.NAME,
12-
include = JsonTypeInfo.As.PROPERTY,
13-
property = "type",
14-
visible = true)
15-
@JsonIgnoreProperties(ignoreUnknown = true)
168
public interface ProcessInfo extends Comparable<ProcessInfo> {
179

1810
String getName();

agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/profiler/triggers/AlertConfigParserTest.java

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,31 @@ void saneDataIsParsed() {
7878
@Test
7979
void requestTriggerIsBuilt() {
8080
AlertingConfig.RequestTrigger requestTrigger =
81-
new AlertingConfig.RequestTrigger(
82-
"test",
83-
AlertingConfig.RequestTriggerType.LATENCY,
84-
new AlertingConfig.RequestFilter(
85-
AlertingConfig.RequestFilterType.NAME_REGEX, "/api/users/.*"),
86-
new AlertingConfig.RequestAggregation(
87-
AlertingConfig.RequestAggregationType.BREACH_RATIO,
88-
7000,
89-
new AlertingConfig.RequestAggregationConfig(10000, 10)),
90-
new AlertingConfig.RequestTriggerThreshold(
91-
AlertingConfig.RequestTriggerThresholdType.GREATER_THAN, 0.75f),
92-
new AlertingConfig.RequestTriggerThrottling(
93-
AlertingConfig.RequestTriggerThrottlingType.FIXED_DURATION_COOLDOWN, 1800),
94-
10);
81+
new AlertingConfig.RequestTrigger()
82+
.setName("test")
83+
.setType(AlertingConfig.RequestTriggerType.LATENCY)
84+
.setFilter(
85+
new AlertingConfig.RequestFilter()
86+
.setType(AlertingConfig.RequestFilterType.NAME_REGEX)
87+
.setValue("/api/users/.*"))
88+
.setAggregation(
89+
new AlertingConfig.RequestAggregation()
90+
.setType(AlertingConfig.RequestAggregationType.BREACH_RATIO)
91+
.setWindowSizeMillis(7000)
92+
.setConfiguration(
93+
new AlertingConfig.RequestAggregationConfig()
94+
.setThresholdMillis(10000)
95+
.setMinimumSamples(10)))
96+
.setThreshold(
97+
new AlertingConfig.RequestTriggerThreshold()
98+
.setType(AlertingConfig.RequestTriggerThresholdType.GREATER_THAN)
99+
.setValue(0.75f))
100+
.setThrottling(
101+
new AlertingConfig.RequestTriggerThrottling()
102+
.setType(AlertingConfig.RequestTriggerThrottlingType.FIXED_DURATION_COOLDOWN)
103+
.setValue(1800))
104+
.setProfileDuration(10);
105+
95106
List<AlertingConfig.RequestTrigger> requestTriggers = new ArrayList<>();
96107
requestTriggers.add(requestTrigger);
97108

0 commit comments

Comments
 (0)