Skip to content

Commit 336cc7d

Browse files
committed
add solr tests + yaml metrics
1 parent 36eed4d commit 336cc7d

File tree

2 files changed

+260
-0
lines changed

2 files changed

+260
-0
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.contrib.jmxscraper.target_systems;
7+
8+
import static io.opentelemetry.contrib.jmxscraper.assertions.DataPointAttributes.attribute;
9+
import static io.opentelemetry.contrib.jmxscraper.assertions.DataPointAttributes.attributeGroup;
10+
import static io.opentelemetry.contrib.jmxscraper.assertions.DataPointAttributes.attributeWithAnyValue;
11+
12+
import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer;
13+
import io.opentelemetry.contrib.jmxscraper.assertions.AttributeMatcher;
14+
import io.opentelemetry.contrib.jmxscraper.assertions.AttributeMatcherGroup;
15+
import java.nio.file.Path;
16+
import java.time.Duration;
17+
import org.testcontainers.containers.GenericContainer;
18+
import org.testcontainers.containers.Network;
19+
import org.testcontainers.containers.wait.strategy.Wait;
20+
21+
public class SolrIntegrationTest extends TargetSystemIntegrationTest {
22+
23+
@Override
24+
protected GenericContainer<?> createTargetContainer(int jmxPort) {
25+
return new GenericContainer<>("solr:8.8.2")
26+
.withNetwork(Network.SHARED)
27+
.withEnv("LOCAL_JMX", "no")
28+
.withEnv("ENABLE_REMOTE_JMX_OPTS", "true")
29+
.withEnv("RMI_PORT", Integer.toString(jmxPort))
30+
.withCommand("solr-precreate", "gettingstarted")
31+
.withExposedPorts(jmxPort)
32+
.withStartupTimeout(Duration.ofMinutes(2))
33+
.waitingFor(Wait.forListeningPort());
34+
}
35+
36+
@Override
37+
protected JmxScraperContainer customizeScraperContainer(
38+
JmxScraperContainer scraper, GenericContainer<?> target, Path tempDir) {
39+
return scraper.withTargetSystem("solr");
40+
}
41+
42+
@Override
43+
protected MetricsVerifier createMetricsVerifier() {
44+
45+
AttributeMatcher coreAttribute = attribute("core", "gettingstarted");
46+
AttributeMatcherGroup[] requestAttributes = requestAttributes(coreAttribute);
47+
AttributeMatcherGroup cacheAttributes =
48+
attributeGroup(coreAttribute, attribute("cache", "searcher"));
49+
50+
return MetricsVerifier.create()
51+
.add(
52+
"solr.document.count",
53+
metric ->
54+
metric
55+
.hasDescription("The total number of indexed documents.")
56+
.hasUnit("{document}")
57+
.isUpDownCounter()
58+
.hasDataPointsWithOneAttribute(coreAttribute))
59+
.add(
60+
"solr.index.size",
61+
metric ->
62+
metric
63+
.hasDescription("The total index size.")
64+
.hasUnit("By")
65+
.isUpDownCounter()
66+
.hasDataPointsWithOneAttribute(coreAttribute))
67+
.add(
68+
"solr.request.count",
69+
metric ->
70+
metric
71+
.hasDescription("The number of queries made.")
72+
.hasUnit("{query}")
73+
.isCounter()
74+
.hasDataPointsWithAttributes(requestAttributes))
75+
.add(
76+
"solr.request.time.average",
77+
metric ->
78+
metric
79+
.hasDescription(
80+
"The average time of a query, based on Solr's histogram configuration.")
81+
.hasUnit("ms")
82+
.isGauge()
83+
.hasDataPointsWithAttributes(requestAttributes))
84+
.add(
85+
"solr.request.error.count",
86+
metric ->
87+
metric
88+
.hasDescription("The number of queries resulting in an error.")
89+
.hasUnit("{query}")
90+
.isCounter()
91+
.hasDataPointsWithAttributes(requestAttributes))
92+
.add(
93+
"solr.request.timeout.count",
94+
metric ->
95+
metric
96+
.hasDescription("The number of queries resulting in a timeout.")
97+
.hasUnit("{query}")
98+
.isCounter()
99+
.hasDataPointsWithAttributes(requestAttributes))
100+
.add(
101+
"solr.cache.eviction.count",
102+
metric ->
103+
metric
104+
.hasDescription("The number of evictions from a cache.")
105+
.hasUnit("{eviction}")
106+
.isCounter()
107+
.hasDataPointsWithAttributes(cacheAttributes))
108+
.add(
109+
"solr.cache.hit.count",
110+
metric ->
111+
metric
112+
.hasDescription("The number of hits for a cache.")
113+
.hasUnit("{hit}")
114+
.isCounter()
115+
.hasDataPointsWithAttributes(cacheAttributes))
116+
.add(
117+
"solr.cache.insert.count",
118+
metric ->
119+
metric
120+
.hasDescription("The number of inserts to a cache.")
121+
.hasUnit("{insert}")
122+
.isCounter()
123+
.hasDataPointsWithAttributes(cacheAttributes))
124+
.add(
125+
"solr.cache.lookup.count",
126+
metric ->
127+
metric
128+
.hasDescription("The number of lookups to a cache.")
129+
.hasUnit("{lookup}")
130+
.isCounter()
131+
.hasDataPointsWithAttributes(cacheAttributes))
132+
.add(
133+
"solr.cache.size",
134+
metric ->
135+
metric
136+
.hasDescription("The size of the cache occupied in memory.")
137+
.hasUnit("By")
138+
.isUpDownCounter()
139+
.hasDataPointsWithAttributes(cacheAttributes));
140+
}
141+
142+
private static AttributeMatcherGroup[] requestAttributes(AttributeMatcher coreAttribute) {
143+
// ignore actual 'handler' values due to high cardinality (10+) and an exact matching makes test
144+
// flaky
145+
return new AttributeMatcherGroup[] {
146+
attributeGroup(coreAttribute, attributeWithAnyValue("handler"), attribute("type", "QUERY")),
147+
attributeGroup(coreAttribute, attributeWithAnyValue("handler"), attribute("type", "UPDATE"))
148+
};
149+
}
150+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
3+
rules:
4+
5+
- bean: solr:dom1=core,dom2=*,category=SEARCHER,scope=searcher,name=numDocs
6+
mapping:
7+
Value:
8+
metric: solr.document.count
9+
type: updowncounter
10+
unit: '{document}'
11+
desc: The total number of indexed documents.
12+
metricAttribute:
13+
core: param(dom2)
14+
15+
- bean: solr:dom1=core,dom2=*,category=INDEX,name=sizeInBytes
16+
mapping:
17+
Value:
18+
metric: solr.index.size
19+
type: updowncounter
20+
unit: By
21+
desc: The total index size.
22+
metricAttribute:
23+
core: param(dom2)
24+
25+
- beans:
26+
- solr:dom1=core,dom2=*,category=QUERY,scope=*,name=requests
27+
- solr:dom1=core,dom2=*,category=UPDATE,scope=*,name=requests
28+
mapping:
29+
Count:
30+
metric: solr.request.count
31+
type: counter
32+
unit: '{query}'
33+
desc: The number of queries made.
34+
metricAttribute:
35+
core: param(dom2)
36+
type: param(category)
37+
handler: param(scope)
38+
39+
- beans:
40+
- solr:dom1=core,dom2=*,category=QUERY,scope=*,name=requestTimes
41+
- solr:dom1=core,dom2=*,category=UPDATE,scope=*,name=requestTimes
42+
mapping:
43+
Mean:
44+
metric: solr.request.time.average
45+
type: gauge
46+
unit: 'ms'
47+
desc: "The average time of a query, based on Solr's histogram configuration."
48+
metricAttribute:
49+
core: param(dom2)
50+
type: param(category)
51+
handler: param(scope)
52+
53+
- beans:
54+
- solr:dom1=core,dom2=*,category=QUERY,scope=*,name=errors
55+
- solr:dom1=core,dom2=*,category=UPDATE,scope=*,name=errors
56+
mapping:
57+
Count:
58+
metric: solr.request.error.count
59+
type: counter
60+
unit: '{query}'
61+
desc: The number of queries resulting in an error.
62+
metricAttribute:
63+
core: param(dom2)
64+
type: param(category)
65+
handler: param(scope)
66+
67+
- beans:
68+
- solr:dom1=core,dom2=*,category=QUERY,scope=*,name=timeouts
69+
- solr:dom1=core,dom2=*,category=UPDATE,scope=*,name=timeouts
70+
mapping:
71+
Count:
72+
metric: solr.request.timeout.count
73+
type: counter
74+
unit: '{query}'
75+
desc: The number of queries resulting in a timeout.
76+
metricAttribute:
77+
core: param(dom2)
78+
type: param(category)
79+
handler: param(scope)
80+
81+
- bean: solr:dom1=core,dom2=*,category=CACHE,scope=*,name=queryResultCache
82+
prefix: solr.cache.
83+
type: counter
84+
metricAttribute:
85+
core: param(dom2)
86+
cache: param(scope)
87+
mapping:
88+
cumulative_evictions:
89+
metric: eviction.count
90+
unit: '{eviction}'
91+
desc: The number of evictions from a cache.
92+
cumulative_hits:
93+
metric: hit.count
94+
unit: '{hit}'
95+
desc: The number of hits for a cache.
96+
cumulative_inserts:
97+
metric: insert.count
98+
unit: '{insert}'
99+
desc: The number of inserts to a cache.
100+
cumulative_lookups:
101+
metric: lookup.count
102+
unit: '{lookup}'
103+
desc: The number of lookups to a cache.
104+
ramBytesUsed:
105+
type: updowncounter
106+
metric: size
107+
unit: 'By'
108+
desc: The size of the cache occupied in memory.
109+
110+

0 commit comments

Comments
 (0)