-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #382 from sentrysoftware/feature/issue-380-impleme…
…nt-state-metrics-compression Issue #380: Implement StateSet metrics compression
- Loading branch information
Showing
21 changed files
with
1,215 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...t/src/main/java/org/sentrysoftware/metricshub/agent/config/StateSetMetricCompression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.sentrysoftware.metricshub.agent.config; | ||
|
||
/*- | ||
* ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ | ||
* MetricsHub Agent | ||
* ჻჻჻჻჻჻ | ||
* Copyright 2023 - 2024 Sentry Software | ||
* ჻჻჻჻჻჻ | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ | ||
*/ | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* StateSetMetricCompression represents the possible compression methods for the state set metrics. | ||
*/ | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class StateSetMetricCompression { | ||
|
||
/** | ||
* Compression mechanism that records the zero value only on the initial state change, | ||
* retaining only the non-zero metric value thereafter. | ||
*/ | ||
public static final String SUPPRESS_ZEROS = "suppressZeros"; | ||
|
||
/** | ||
* No compression, all zero and non-zero values are recorded. | ||
*/ | ||
public static final String NONE = "none"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...trysoftware/metricshub/agent/service/signal/AbstractNotCompressedStateMetricObserver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.sentrysoftware.metricshub.agent.service.signal; | ||
|
||
/*- | ||
* ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ | ||
* MetricsHub Agent | ||
* ჻჻჻჻჻჻ | ||
* Copyright 2023 - 2024 Sentry Software | ||
* ჻჻჻჻჻჻ | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ | ||
*/ | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.metrics.Meter; | ||
import io.opentelemetry.api.metrics.ObservableDoubleMeasurement; | ||
import org.sentrysoftware.metricshub.engine.telemetry.metric.StateSetMetric; | ||
|
||
/** | ||
* Abstract class for observing state set metrics without applying any compression. | ||
* Extends {@link AbstractStateMetricObserver}. | ||
*/ | ||
public abstract class AbstractNotCompressedStateMetricObserver extends AbstractStateMetricObserver { | ||
|
||
/** | ||
* Constructs a new {@code AbstractNotCompressedStateSetMetricObserver} with the specified parameters. | ||
* | ||
* @param meter The OpenTelemetry meter to use for creating the metric. | ||
* @param attributes The attributes to associate with the metric. | ||
* @param metricName The name of the metric. | ||
* @param unit The unit of the metric. | ||
* @param description The description of the metric. | ||
* @param state The state used to observe the metric. E.g. "ok". | ||
* @param metric The StateSetMetric to observe. | ||
*/ | ||
protected AbstractNotCompressedStateMetricObserver( | ||
final Meter meter, | ||
final Attributes attributes, | ||
final String metricName, | ||
final String unit, | ||
final String description, | ||
final String state, | ||
final StateSetMetric metric | ||
) { | ||
super(meter, attributes, metricName, unit, description, state, metric); | ||
} | ||
|
||
@Override | ||
protected void recordMetricValue(final ObservableDoubleMeasurement recorder, final String value) { | ||
recorder.record(value.equalsIgnoreCase(state) ? 1 : 0, attributes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...trysoftware/metricshub/agent/service/signal/AbstractSuppressZerosStateMetricObserver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.sentrysoftware.metricshub.agent.service.signal; | ||
|
||
/*- | ||
* ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ | ||
* MetricsHub Agent | ||
* ჻჻჻჻჻჻ | ||
* Copyright 2023 - 2024 Sentry Software | ||
* ჻჻჻჻჻჻ | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ | ||
*/ | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.metrics.Meter; | ||
import io.opentelemetry.api.metrics.ObservableDoubleMeasurement; | ||
import org.sentrysoftware.metricshub.engine.telemetry.metric.StateSetMetric; | ||
|
||
/** | ||
* Abstract class for observing state set metrics by applying a suppression of zero values. | ||
* Extends {@link AbstractStateMetricObserver}. | ||
*/ | ||
public abstract class AbstractSuppressZerosStateMetricObserver extends AbstractStateMetricObserver { | ||
|
||
/** | ||
* Constructs a new {@code AbstractSuppressZerosStateMetricObserver} with the specified parameters. | ||
* | ||
* @param meter The OpenTelemetry meter to use for creating the metric. | ||
* @param attributes The attributes to associate with the metric. | ||
* @param metricName The name of the metric. | ||
* @param unit The unit of the metric. | ||
* @param description The description of the metric. | ||
* @param state The state used to observe the metric. E.g. "ok". | ||
* @param metric The StateSetMetric to observe. | ||
*/ | ||
protected AbstractSuppressZerosStateMetricObserver( | ||
final Meter meter, | ||
final Attributes attributes, | ||
final String metricName, | ||
final String unit, | ||
final String description, | ||
final String state, | ||
final StateSetMetric metric | ||
) { | ||
super(meter, attributes, metricName, unit, description, state, metric); | ||
} | ||
|
||
@Override | ||
protected void recordMetricValue(final ObservableDoubleMeasurement recorder, final String value) { | ||
if (value.equalsIgnoreCase(state)) { | ||
recorder.record(1, attributes); | ||
} else { | ||
final String previousValue = metric.getPreviousValue(); | ||
if (previousValue != null && !previousValue.equalsIgnoreCase(value) && previousValue.equalsIgnoreCase(state)) { | ||
recorder.record(0, attributes); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...ntrysoftware/metricshub/agent/service/signal/CounterSuppressZerosStateMetricObserver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.sentrysoftware.metricshub.agent.service.signal; | ||
|
||
/*- | ||
* ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ | ||
* MetricsHub Agent | ||
* ჻჻჻჻჻჻ | ||
* Copyright 2023 - 2024 Sentry Software | ||
* ჻჻჻჻჻჻ | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ | ||
*/ | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.metrics.Meter; | ||
import lombok.Builder; | ||
import org.sentrysoftware.metricshub.engine.telemetry.metric.StateSetMetric; | ||
|
||
/** | ||
* Observer for a counter state metric with suppression of zero values, extending {@link AbstractSuppressZerosStateMetricObserver}. | ||
* This observer initializes the metric and provides a callback for observing state changes. | ||
*/ | ||
public class CounterSuppressZerosStateMetricObserver extends AbstractSuppressZerosStateMetricObserver { | ||
|
||
/** | ||
* Constructs a {@code CounterSuppressZerosStateMetricObserver} with the specified parameters. | ||
* | ||
* @param meter The OpenTelemetry meter to use for creating the metric. | ||
* @param attributes The attributes to associate with the metric. | ||
* @param metricName The name of the metric. | ||
* @param unit The unit of the metric. | ||
* @param description The description of the metric. | ||
* @param state The state used to observe the metric. E.g. "ok". | ||
* @param metric The StateSetMetric to observe. | ||
*/ | ||
@Builder(setterPrefix = "with") | ||
public CounterSuppressZerosStateMetricObserver( | ||
final Meter meter, | ||
final Attributes attributes, | ||
final String metricName, | ||
final String unit, | ||
final String description, | ||
final String state, | ||
final StateSetMetric metric | ||
) { | ||
super(meter, attributes, metricName, unit, description, state, metric); | ||
} | ||
|
||
@Override | ||
public void init() { | ||
newDoubleCounterBuilder().buildWithCallback(super::observeStateMetric); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.