Skip to content

Commit 4d9a69d

Browse files
Add a counter that records the number of times the connection was not established successfully, with an error.code dimension recording the code of the error reported
1 parent 2039bd6 commit 4d9a69d

File tree

9 files changed

+612
-50
lines changed

9 files changed

+612
-50
lines changed

ibm-mq-metrics/docs/metrics.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,3 +799,21 @@
799799
| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
800800
|---|---|---|---|---|---|
801801
| `ibm.mq.queue.manager` | string | The name of the IBM queue manager | `MQ1` | `Required` | ![Development](https://img.shields.io/badge/-development-blue) |
802+
803+
804+
805+
## Metric `mq.connection.errors`
806+
807+
| Name | Instrument Type | Unit (UCUM) | Description | Stability |
808+
| -------- | --------------- | ----------- | -------------- | --------- |
809+
| `mq.connection.errors` | Counter | `{errors}` | Number of connection errors | ![Development](https://img.shields.io/badge/-development-blue) |
810+
811+
812+
### `mq.connection.errors` Attributes
813+
814+
| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
815+
|---|---|---|---|---|---|
816+
| `error.code` | string | The reason code associated with an error | `2038`; `2543`; `2009` | `Required` | ![Development](https://img.shields.io/badge/-development-blue) |
817+
| `ibm.mq.queue.manager` | string | The name of the IBM queue manager | `MQ1` | `Required` | ![Development](https://img.shields.io/badge/-development-blue) |
818+
819+

ibm-mq-metrics/model/attributes.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,9 @@ groups:
7373
note: This is duplicated from otel semantic-conventions.
7474
stability: development
7575
examples: [ "Wordle", "JMSService" ]
76+
- id: error.code
77+
type: string
78+
brief: >
79+
The reason code associated with an error
80+
stability: development
81+
examples: [ "2038", "2543", "2009" ]

ibm-mq-metrics/model/metrics.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,3 +609,15 @@ groups:
609609
attributes:
610610
- ref: ibm.mq.queue.manager
611611
requirement_level: required
612+
- id: mq.connection.errors
613+
type: metric
614+
metric_name: mq.connection.errors
615+
stability: development
616+
brief: "Number of connection errors"
617+
instrument: counter
618+
unit: "{errors}"
619+
attributes:
620+
- ref: ibm.mq.queue.manager
621+
requirement_level: required
622+
- ref: error.code
623+
requirement_level: required

ibm-mq-metrics/src/integrationTest/java/io/opentelemetry/ibm/mq/integration/tests/WMQMonitorIntegrationTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818
import com.ibm.mq.headers.pcf.PCFException;
1919
import com.ibm.mq.headers.pcf.PCFMessage;
2020
import com.ibm.mq.headers.pcf.PCFMessageAgent;
21+
import io.opentelemetry.api.common.AttributeKey;
2122
import io.opentelemetry.api.metrics.Meter;
2223
import io.opentelemetry.ibm.mq.config.QueueManager;
2324
import io.opentelemetry.ibm.mq.opentelemetry.ConfigWrapper;
2425
import io.opentelemetry.ibm.mq.opentelemetry.Main;
2526
import io.opentelemetry.ibm.mq.util.WmqUtil;
27+
import io.opentelemetry.sdk.metrics.data.LongPointData;
2628
import io.opentelemetry.sdk.metrics.data.MetricData;
29+
import io.opentelemetry.sdk.metrics.data.SumData;
2730
import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension;
2831
import java.io.File;
2932
import java.net.URISyntaxException;
@@ -281,4 +284,34 @@ void test_otlphttp() throws Exception {
281284
// reads a value from the heartbeat gauge
282285
assertThat(metricNames).contains("ibm.mq.heartbeat");
283286
}
287+
288+
@Test
289+
void test_bad_connection() throws Exception {
290+
logger.info("\n\n\n\n\n\nRunning test: test_bad_connection");
291+
String configFile = getConfigFile("conf/test-bad-config.yml");
292+
293+
ConfigWrapper config = ConfigWrapper.parse(configFile);
294+
Meter meter = otelTesting.getOpenTelemetry().getMeter("opentelemetry.io/mq");
295+
TestWMQMonitor monitor = new TestWMQMonitor(config, meter, service);
296+
monitor.runTest();
297+
298+
List<MetricData> data = otelTesting.getMetrics();
299+
300+
assertThat(data).isNotEmpty();
301+
assertThat(data).hasSize(2);
302+
303+
SumData<LongPointData> connectionErrors = null;
304+
for (MetricData metricData : data) {
305+
if ("mq.connection.errors".equals(metricData.getName())) {
306+
connectionErrors = (SumData<LongPointData>) metricData.getData();
307+
}
308+
}
309+
310+
assertThat(connectionErrors).isNotNull();
311+
312+
LongPointData metricPoint = connectionErrors.getPoints().iterator().next();
313+
String value = metricPoint.getAttributes().get(AttributeKey.stringKey("error.code"));
314+
315+
assertThat(value).isEqualTo("2538");
316+
}
284317
}

0 commit comments

Comments
 (0)