Skip to content

Commit d028816

Browse files
committed
Reshaped batch size metric response from {pipeline-name}->events->batch_size->[75Percentile, 90Percentile] to {pipeline_name}->batch->event_count->[p75, p90]
1 parent 1e27899 commit d028816

File tree

8 files changed

+40
-21
lines changed

8 files changed

+40
-21
lines changed

logstash-core/lib/logstash/api/commands/stats.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def plugin_stats(stats, plugin_type)
174174

175175
def report(stats, extended_stats = nil, opts = {})
176176
ret = {
177+
:batch => stats[:batch],
177178
:events => stats[:events],
178179
:flow => stats[:flow],
179180
:plugins => {

logstash-core/src/main/java/org/logstash/execution/AbstractPipelineExt.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ private AbstractPipelineExt initialize(final ThreadContext context,
290290

291291

292292
// init histogram sample
293-
final RubySymbol[] eventsNamespace = buildNamespace(EVENTS_KEY);
294-
initOrGetHistogramMetric(context, eventsNamespace, BATCH_SIZE_KEY);
293+
final RubySymbol[] batchNamespace = buildNamespace(BATCH_KEY);
294+
initOrGetHistogramMetric(context, batchNamespace, BATCH_EVENT_COUNT_KEY);
295295

296296
return this;
297297
}
@@ -324,8 +324,8 @@ public final IRubyObject openQueue(final ThreadContext context) {
324324
new IRubyObject[]{
325325
STATS_KEY,
326326
PIPELINES_KEY,
327-
pipelineId.convertToString().intern(),
328-
EVENTS_KEY
327+
pipelineId.convertToString().intern()/*,
328+
EVENTS_KEY*/
329329
}
330330
)
331331
)

logstash-core/src/main/java/org/logstash/execution/QueueReadClientBase.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
import java.util.concurrent.ConcurrentHashMap;
4343
import java.util.concurrent.TimeUnit;
4444

45+
import static org.logstash.instrument.metrics.MetricKeys.BATCH_KEY;
46+
import static org.logstash.instrument.metrics.MetricKeys.EVENTS_KEY;
47+
4548
/**
4649
* Common code shared by Persistent and In-Memory queues clients implementation
4750
* */
@@ -101,11 +104,14 @@ public IRubyObject setEventsMetric(final IRubyObject metric) {
101104
@JRubyMethod(name = "set_pipeline_metric")
102105
public IRubyObject setPipelineMetric(final IRubyObject metric) {
103106
final AbstractNamespacedMetricExt namespacedMetric = (AbstractNamespacedMetricExt) metric;
107+
ThreadContext context = metric.getRuntime().getCurrentContext();
108+
AbstractNamespacedMetricExt eventsNamespace = namespacedMetric.namespace(context, EVENTS_KEY);
109+
AbstractNamespacedMetricExt batchNamespace = namespacedMetric.namespace(context, BATCH_KEY);
104110
synchronized(namespacedMetric.getMetric()) {
105-
pipelineMetricOut = LongCounter.fromRubyBase(namespacedMetric, MetricKeys.OUT_KEY);
106-
pipelineMetricFiltered = LongCounter.fromRubyBase(namespacedMetric, MetricKeys.FILTERED_KEY);
107-
pipelineMetricTime = TimerMetric.fromRubyBase(namespacedMetric, MetricKeys.DURATION_IN_MILLIS_KEY);
108-
pipelineMetricBatch = HistogramMetric.fromRubyBase(namespacedMetric, MetricKeys.BATCH_SIZE_KEY);
111+
pipelineMetricOut = LongCounter.fromRubyBase(eventsNamespace, MetricKeys.OUT_KEY);
112+
pipelineMetricFiltered = LongCounter.fromRubyBase(eventsNamespace, MetricKeys.FILTERED_KEY);
113+
pipelineMetricTime = TimerMetric.fromRubyBase(eventsNamespace, MetricKeys.DURATION_IN_MILLIS_KEY);
114+
pipelineMetricBatch = HistogramMetric.fromRubyBase(batchNamespace, MetricKeys.BATCH_EVENT_COUNT_KEY);
109115
}
110116
return this;
111117
}

logstash-core/src/main/java/org/logstash/instrument/metrics/MetricKeys.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,7 @@ private MetricKeys() {
116116

117117
public static final RubySymbol WRITES_IN_KEY = RubyUtil.RUBY.newSymbol("writes_in");
118118

119-
public static final RubySymbol BATCH_SIZE_KEY = RubyUtil.RUBY.newSymbol("batch_size");
119+
public static final RubySymbol BATCH_EVENT_COUNT_KEY = RubyUtil.RUBY.newSymbol("event_count");
120+
121+
public static final RubySymbol BATCH_KEY = RubyUtil.RUBY.newSymbol("batch");
120122
}

logstash-core/src/main/java/org/logstash/instrument/metrics/histogram/HistogramSnapshot.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.logstash.instrument.metrics.histogram;
22

3+
import com.fasterxml.jackson.annotation.JsonProperty;
34
import org.HdrHistogram.Histogram;
45

56
import java.io.Serializable;
@@ -19,10 +20,12 @@ public HistogramSnapshot(Histogram hdrHistogram) {
1920
percentile90 = hdrHistogram.getValueAtPercentile(90);
2021
}
2122

23+
@JsonProperty("p75")
2224
public double get75Percentile() {
2325
return percentile75;
2426
}
2527

28+
@JsonProperty("p90")
2629
public double get90Percentile() {
2730
return percentile90;
2831
}

logstash-core/src/test/java/org/logstash/ext/JrubyMemoryReadClientExtTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import static org.hamcrest.CoreMatchers.is;
4141
import static org.hamcrest.MatcherAssert.assertThat;
4242
import static org.junit.Assert.assertEquals;
43+
import static org.logstash.instrument.metrics.MetricKeys.BATCH_KEY;
4344

4445
/**
4546
* Tests for {@link JrubyMemoryReadClientExt}.
@@ -80,7 +81,8 @@ public void givenNonEmptyQueueAndEnabledBatchSizeMetricThenHistogramContainsData
8081
final QueueBatch batch = client.readBatch();
8182
assertEquals(1, batch.filteredSize());
8283

83-
HistogramMetric histogram = HistogramMetric.fromRubyBase(metric, MetricKeys.BATCH_SIZE_KEY);
84+
ThreadContext context = metric.getRuntime().getCurrentContext();
85+
HistogramMetric histogram = HistogramMetric.fromRubyBase(metric.namespace(context, BATCH_KEY), MetricKeys.BATCH_EVENT_COUNT_KEY);
8486
HistogramSnapshot metricSnapshot = histogram.getValue();
8587
assertEquals(1.0, metricSnapshot.get75Percentile(), 0.0001);
8688
assertEquals(1.0, metricSnapshot.get90Percentile(), 0.0001);
@@ -100,7 +102,8 @@ public void givenNonEmptyQueueAndDisabledBatchSizeMetricThenHistogramIsNotPopula
100102
final QueueBatch batch = client.readBatch();
101103
assertEquals(1, batch.filteredSize());
102104

103-
HistogramMetric histogram = HistogramMetric.fromRubyBase(metric, MetricKeys.BATCH_SIZE_KEY);
105+
ThreadContext context = metric.getRuntime().getCurrentContext();
106+
HistogramMetric histogram = HistogramMetric.fromRubyBase(metric.namespace(context, BATCH_KEY), MetricKeys.BATCH_EVENT_COUNT_KEY);
104107
HistogramSnapshot metricSnapshot = histogram.getValue();
105108
assertEquals(0.0, metricSnapshot.get75Percentile(), 0.0001);
106109
assertEquals(0.0, metricSnapshot.get90Percentile(), 0.0001);

logstash-core/src/test/java/org/logstash/instrument/metrics/MockNamespacedMetric.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public AbstractMetricExt getMetric() {
9393

9494
@Override
9595
protected AbstractNamespacedMetricExt createNamespaced(ThreadContext context, IRubyObject name) {
96-
return null;
96+
return this;
9797
}
9898

9999
@Override

x-pack/spec/monitoring/schemas/monitoring_document_schema.json

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,26 @@
99
"successes": { "type": "number" }
1010
}
1111
},
12+
"batch": {
13+
"type": "object",
14+
"properties": {
15+
"event_count": {
16+
"type": "object",
17+
"require": ["p75", "p90"],
18+
"properties": {
19+
"p75": { "type": "number" },
20+
"p90": { "type": "number" }
21+
}
22+
}
23+
},
1224
"events": {
1325
"type": "object",
1426
"required": ["filtered", "in", "duration_in_millis", "out"],
1527
"properties": {
1628
"filtered": { "type": "number" },
1729
"in": { "type": "number" },
1830
"duration_in_millis": { "type": "number" },
19-
"out": { "type": "number" },
20-
"batch_size": {
21-
"type": "object",
22-
"require": ["75Percentile", "90Percentile"],
23-
"properties": {
24-
"75Percentile": { "type": "number" },
25-
"90Percentile": { "type": "number" }
26-
}
27-
}
31+
"out": { "type": "number" }
2832
}
2933
}
3034
},

0 commit comments

Comments
 (0)