Skip to content

Commit 3c7da58

Browse files
authored
Initial proposal for providing access to JFR profiles from within Application Insights (#1513)
1 parent 220a436 commit 3c7da58

File tree

96 files changed

+5665
-17
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+5665
-17
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
group = 'io.opentelemetry.javaagent'
2+
3+
apply from: "$buildScriptsDir/common-java.gradle"
4+
apply from: "$buildScriptsDir/publishing.gradle"
5+
6+
dependencies {
7+
testCompile group: 'junit', name: 'junit', version: '4.12'
8+
testCompile 'org.mockito:mockito-core:1.10.19'
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This is a Gradle generated file for dependency locking.
2+
# Manual edits can break the build and are not advised.
3+
# This file is expected to be part of source control.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This is a Gradle generated file for dependency locking.
2+
# Manual edits can break the build and are not advised.
3+
# This file is expected to be part of source control.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* ApplicationInsights-Java
3+
* Copyright (c) Microsoft Corporation
4+
* All rights reserved.
5+
*
6+
* MIT License
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
8+
* software and associated documentation files (the ""Software""), to deal in the Software
9+
* without restriction, including without limitation the rights to use, copy, modify, merge,
10+
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit
11+
* persons to whom the Software is furnished to do so, subject to the following conditions:
12+
* The above copyright notice and this permission notice shall be included in all copies or
13+
* substantial portions of the Software.
14+
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16+
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
17+
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19+
* DEALINGS IN THE SOFTWARE.
20+
*/
21+
package com.microsoft.applicationinsights.alerting.alert;
22+
23+
import com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration;
24+
25+
/**
26+
* Represents a breach of an alert threshold
27+
*/
28+
public class AlertBreach {
29+
private final AlertMetricType type;
30+
31+
// Value of the telemetry at the time of the breach
32+
private final double alertValue;
33+
34+
private final AlertConfiguration alertConfiguration;
35+
36+
// CPU usage at the time of the breach
37+
private final double cpuUsage;
38+
39+
// MEMORY usage at the time of the breach
40+
private final double memoryUsage;
41+
42+
public AlertBreach(AlertMetricType type, double alertValue, AlertConfiguration alertConfiguration) {
43+
this(type, alertValue, alertConfiguration, 0, 0);
44+
}
45+
46+
public AlertBreach(AlertMetricType type, double alertValue, AlertConfiguration alertConfiguration, double cpuUsage, double memoryUsage) {
47+
this.type = type;
48+
this.alertValue = alertValue;
49+
this.alertConfiguration = alertConfiguration;
50+
this.cpuUsage = cpuUsage;
51+
this.memoryUsage = memoryUsage;
52+
53+
}
54+
55+
public AlertConfiguration getAlertConfiguration() {
56+
return alertConfiguration;
57+
}
58+
59+
public double getAlertValue() {
60+
return alertValue;
61+
}
62+
63+
public AlertMetricType getType() {
64+
return type;
65+
}
66+
67+
public AlertBreach withCpuMetric(double cpuUsage) {
68+
return new AlertBreach(type, alertValue, alertConfiguration, cpuUsage, memoryUsage);
69+
}
70+
71+
public AlertBreach withMemoryMetric(double memoryUsage) {
72+
return new AlertBreach(type, alertValue, alertConfiguration, cpuUsage, memoryUsage);
73+
}
74+
75+
public String getTriggerName() {
76+
return "JFR-" + type.name();
77+
}
78+
79+
public double getCpuMetric() {
80+
return cpuUsage;
81+
}
82+
83+
public double getMemoryUsage() {
84+
return memoryUsage;
85+
}
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* ApplicationInsights-Java
3+
* Copyright (c) Microsoft Corporation
4+
* All rights reserved.
5+
*
6+
* MIT License
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
8+
* software and associated documentation files (the ""Software""), to deal in the Software
9+
* without restriction, including without limitation the rights to use, copy, modify, merge,
10+
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit
11+
* persons to whom the Software is furnished to do so, subject to the following conditions:
12+
* The above copyright notice and this permission notice shall be included in all copies or
13+
* substantial portions of the Software.
14+
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16+
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
17+
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19+
* DEALINGS IN THE SOFTWARE.
20+
*/
21+
package com.microsoft.applicationinsights.alerting.alert;
22+
23+
public enum AlertMetricType {
24+
CPU,
25+
MEMORY,
26+
PERIODIC,
27+
MANUAL
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
/*
2+
* ApplicationInsights-Java
3+
* Copyright (c) Microsoft Corporation
4+
* All rights reserved.
5+
*
6+
* MIT License
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
8+
* software and associated documentation files (the ""Software""), to deal in the Software
9+
* without restriction, including without limitation the rights to use, copy, modify, merge,
10+
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit
11+
* persons to whom the Software is furnished to do so, subject to the following conditions:
12+
* The above copyright notice and this permission notice shall be included in all copies or
13+
* substantial portions of the Software.
14+
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16+
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
17+
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19+
* DEALINGS IN THE SOFTWARE.
20+
*/
21+
package com.microsoft.applicationinsights.alerting.config;
22+
23+
import java.util.Objects;
24+
25+
import com.microsoft.applicationinsights.alerting.alert.AlertMetricType;
26+
27+
/**
28+
* Contains the overall configuration of the entire alerting subsystem
29+
*/
30+
public class AlertingConfiguration {
31+
32+
// Alert configuration for CPU telemetry
33+
private final AlertConfiguration cpuAlert;
34+
35+
// Alert configuration for MEMORY telemetry
36+
private final AlertConfiguration memoryAlert;
37+
38+
// Alert configuration for the periodic profiling
39+
private final DefaultConfiguration defaultConfiguration;
40+
41+
// Alert configuration for manual profiling
42+
private final CollectionPlanConfiguration collectionPlanConfiguration;
43+
44+
public AlertingConfiguration(AlertConfiguration cpuAlert, AlertConfiguration memoryAlert, DefaultConfiguration defaultConfiguration,
45+
CollectionPlanConfiguration collectionPlanConfiguration) {
46+
this.cpuAlert = cpuAlert;
47+
this.memoryAlert = memoryAlert;
48+
this.defaultConfiguration = defaultConfiguration;
49+
this.collectionPlanConfiguration = collectionPlanConfiguration;
50+
}
51+
52+
public DefaultConfiguration getDefaultConfiguration() {
53+
return defaultConfiguration;
54+
}
55+
56+
public AlertConfiguration getCpuAlert() {
57+
return cpuAlert;
58+
}
59+
60+
public AlertConfiguration getMemoryAlert() {
61+
return memoryAlert;
62+
}
63+
64+
public CollectionPlanConfiguration getCollectionPlanConfiguration() {
65+
return collectionPlanConfiguration;
66+
}
67+
68+
@Override public boolean equals(Object o) {
69+
if (this == o) return true;
70+
if (o == null || getClass() != o.getClass()) return false;
71+
AlertingConfiguration that = (AlertingConfiguration) o;
72+
return Objects.equals(cpuAlert, that.cpuAlert) && Objects.equals(memoryAlert, that.memoryAlert) && Objects.equals(defaultConfiguration, that.defaultConfiguration) &&
73+
Objects.equals(collectionPlanConfiguration, that.collectionPlanConfiguration);
74+
}
75+
76+
@Override public int hashCode() {
77+
return Objects.hash(cpuAlert, memoryAlert, defaultConfiguration, collectionPlanConfiguration);
78+
}
79+
80+
/**
81+
* Alert configuration for a given telemetry type
82+
*/
83+
public static class AlertConfiguration {
84+
85+
private final AlertMetricType type;
86+
private final boolean enabled;
87+
private final float threshold;
88+
private final long profileDuration;
89+
private final long cooldown;
90+
91+
public AlertConfiguration(AlertMetricType type, boolean enabled, float threshold, long profileDuration, long cooldown) {
92+
this.type = type;
93+
this.enabled = enabled;
94+
this.threshold = threshold;
95+
this.profileDuration = profileDuration;
96+
this.cooldown = cooldown;
97+
}
98+
99+
public boolean isEnabled() {
100+
return enabled;
101+
}
102+
103+
public float getThreshold() {
104+
return threshold;
105+
}
106+
107+
public long getProfileDuration() {
108+
return profileDuration;
109+
}
110+
111+
public long getCooldown() {
112+
return cooldown;
113+
}
114+
115+
@Override public boolean equals(Object o) {
116+
if (this == o) return true;
117+
if (o == null || getClass() != o.getClass()) return false;
118+
AlertConfiguration that = (AlertConfiguration) o;
119+
return enabled == that.enabled &&
120+
Float.compare(that.threshold, threshold) == 0 &&
121+
profileDuration == that.profileDuration &&
122+
cooldown == that.cooldown;
123+
}
124+
125+
@Override public int hashCode() {
126+
return Objects.hash(enabled, threshold, profileDuration, cooldown);
127+
}
128+
129+
public AlertMetricType getType() {
130+
return type;
131+
}
132+
133+
@Override public String toString() {
134+
return "AlertConfiguration{" +
135+
"type=" + type +
136+
", enabled=" + enabled +
137+
", threshold=" + threshold +
138+
", profileDuration=" + profileDuration +
139+
", cooldown=" + cooldown +
140+
'}';
141+
}
142+
}
143+
144+
public static class AlertConfigurationBuilder {
145+
private boolean enabled;
146+
private float threshold;
147+
private long profileDuration;
148+
private long cooldown;
149+
private AlertMetricType type;
150+
151+
public AlertConfigurationBuilder setEnabled(boolean enabled) {
152+
this.enabled = enabled;
153+
return this;
154+
}
155+
156+
public AlertConfigurationBuilder setThreshold(float threshold) {
157+
this.threshold = threshold;
158+
return this;
159+
}
160+
161+
public AlertConfigurationBuilder setProfileDuration(long profileDuration) {
162+
this.profileDuration = profileDuration;
163+
return this;
164+
}
165+
166+
public AlertConfigurationBuilder setCooldown(long cooldown) {
167+
this.cooldown = cooldown;
168+
return this;
169+
}
170+
171+
public AlertConfigurationBuilder setType(AlertMetricType type) {
172+
this.type = type;
173+
return this;
174+
}
175+
176+
public AlertConfiguration createAlertConfiguration() {
177+
return new AlertConfiguration(type, enabled, threshold, profileDuration, cooldown);
178+
}
179+
}
180+
}

0 commit comments

Comments
 (0)