From 424e216d3078786439c775c29b170d8390da0278 Mon Sep 17 00:00:00 2001 From: "nikita.smirnov" Date: Fri, 12 Apr 2024 15:31:11 +0400 Subject: [PATCH 1/4] Use box name from `box.json` config as RabbitMQ connection name --- README.md | 6 +++++- .../schema/box/configuration/BoxConfiguration.java | 11 ++++++----- .../common/schema/factory/AbstractCommonFactory.java | 4 ++-- .../impl/rabbitmq/connection/ConnectionManager.java | 6 +++--- .../rabbitmq/AbstractRabbitRouterIntegrationTest.kt | 3 ++- .../impl/rabbitmq/connection/TestConnectionManager.kt | 5 ++++- .../group/IntegrationTestRabbitMessageBatchRouter.kt | 3 ++- .../TransportGroupBatchRouterIntegrationTest.kt | 3 ++- 8 files changed, 26 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f1300457d..c12482e6b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# th2 common library (Java) (5.10.0) +# th2 common library (Java) (5.10.1) ## Usage @@ -507,6 +507,10 @@ dependencies { ## Release notes +### 5.10.1-dev + ++ Use box name from `box.json` config as RabbitMQ connection name + ### 5.10.0-dev + Update bom: 4.5.0 -> 4.6.0 diff --git a/src/main/java/com/exactpro/th2/common/schema/box/configuration/BoxConfiguration.java b/src/main/java/com/exactpro/th2/common/schema/box/configuration/BoxConfiguration.java index d35a2db58..6a44d5146 100644 --- a/src/main/java/com/exactpro/th2/common/schema/box/configuration/BoxConfiguration.java +++ b/src/main/java/com/exactpro/th2/common/schema/box/configuration/BoxConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2021 Exactpro (Exactpro Systems Limited) + * Copyright 2021-2024 Exactpro (Exactpro Systems Limited) * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -17,28 +17,29 @@ import com.exactpro.th2.common.schema.configuration.Configuration; import com.fasterxml.jackson.annotation.JsonProperty; - import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import static com.exactpro.th2.common.event.EventUtils.requireNonBlankBookName; +import static org.apache.commons.lang3.StringUtils.defaultIfBlank; public class BoxConfiguration extends Configuration { public static final String DEFAULT_BOOK_NAME = "test_book"; + public static final String DEFAULT_BOX_NAME = "th2_component"; @JsonProperty - private String boxName = null; + private String boxName = DEFAULT_BOX_NAME; @JsonProperty private String bookName = DEFAULT_BOOK_NAME; - @Nullable + @NotNull public String getBoxName() { return boxName; } public void setBoxName(@Nullable String boxName) { - this.boxName = boxName; + this.boxName = defaultIfBlank(boxName, DEFAULT_BOX_NAME); } @NotNull diff --git a/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java b/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java index d1d82e338..8545a0def 100644 --- a/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java +++ b/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2023 Exactpro (Exactpro Systems Limited) + * Copyright 2020-2024 Exactpro (Exactpro Systems Limited) * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -658,7 +658,7 @@ protected PrometheusConfiguration loadPrometheusConfiguration() { } protected ConnectionManager createRabbitMQConnectionManager() { - return new ConnectionManager(getRabbitMqConfiguration(), getConnectionManagerConfiguration()); + return new ConnectionManager(getBoxConfiguration().getBoxName(), getRabbitMqConfiguration(), getConnectionManagerConfiguration()); } protected ConnectionManager getRabbitMqConnectionManager() { diff --git a/src/main/java/com/exactpro/th2/common/schema/message/impl/rabbitmq/connection/ConnectionManager.java b/src/main/java/com/exactpro/th2/common/schema/message/impl/rabbitmq/connection/ConnectionManager.java index e209c4b4c..aea3e5304 100644 --- a/src/main/java/com/exactpro/th2/common/schema/message/impl/rabbitmq/connection/ConnectionManager.java +++ b/src/main/java/com/exactpro/th2/common/schema/message/impl/rabbitmq/connection/ConnectionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2023 Exactpro (Exactpro Systems Limited) + * Copyright 2020-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -110,7 +110,7 @@ public ConnectionManagerConfiguration getConfiguration() { return configuration; } - public ConnectionManager(@NotNull RabbitMQConfiguration rabbitMQConfiguration, @NotNull ConnectionManagerConfiguration connectionManagerConfiguration) { + public ConnectionManager(@NotNull String connectionName, @NotNull RabbitMQConfiguration rabbitMQConfiguration, @NotNull ConnectionManagerConfiguration connectionManagerConfiguration) { Objects.requireNonNull(rabbitMQConfiguration, "RabbitMQ configuration cannot be null"); this.configuration = Objects.requireNonNull(connectionManagerConfiguration, "Connection manager configuration can not be null"); @@ -218,7 +218,7 @@ private void turnOffReadiness(Throwable exception) { factory.setSharedExecutor(sharedExecutor); try { - connection = factory.newConnection(); + connection = factory.newConnection(connectionName); LOGGER.info("Created RabbitMQ connection {} [{}]", connection, connection.hashCode()); addShutdownListenerToConnection(this.connection); addBlockedListenersToConnection(this.connection); diff --git a/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/AbstractRabbitRouterIntegrationTest.kt b/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/AbstractRabbitRouterIntegrationTest.kt index 2a0864404..115b1587a 100644 --- a/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/AbstractRabbitRouterIntegrationTest.kt +++ b/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/AbstractRabbitRouterIntegrationTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2023 Exactpro (Exactpro Systems Limited) + * Copyright 2023-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -160,6 +160,7 @@ class AbstractRabbitRouterIntegrationTest { prefetchCount: Int = DEFAULT_PREFETCH_COUNT, confirmationTimeout: Duration = DEFAULT_CONFIRMATION_TIMEOUT ) = ConnectionManager( + "test-connection", RabbitMQConfiguration( host = rabbitMQContainer.host, vHost = "", diff --git a/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/connection/TestConnectionManager.kt b/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/connection/TestConnectionManager.kt index 342b58d9a..7448ef191 100644 --- a/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/connection/TestConnectionManager.kt +++ b/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/connection/TestConnectionManager.kt @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Exactpro (Exactpro Systems Limited) + * Copyright 2022-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -418,6 +418,7 @@ class TestConnectionManager { declareQueue(it, queueName) LOGGER.info { "Started with port ${it.amqpPort}" } ConnectionManager( + "test-connection", RabbitMQConfiguration( host = it.host, vHost = "", @@ -894,6 +895,7 @@ class TestConnectionManager { private fun createConnectionManager(container: RabbitMQContainer, configuration: ConnectionManagerConfiguration) = ConnectionManager( + "test-connection", RabbitMQConfiguration( host = container.host, vHost = "", @@ -970,6 +972,7 @@ class TestConnectionManager { prefetchCount: Int = DEFAULT_PREFETCH_COUNT, confirmationTimeout: Duration = DEFAULT_CONFIRMATION_TIMEOUT, ) = ConnectionManager( + "test-connection", RabbitMQConfiguration( host = rabbitMQContainer.host, vHost = "", diff --git a/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/group/IntegrationTestRabbitMessageBatchRouter.kt b/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/group/IntegrationTestRabbitMessageBatchRouter.kt index b9e953ac5..3f654b9fe 100644 --- a/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/group/IntegrationTestRabbitMessageBatchRouter.kt +++ b/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/group/IntegrationTestRabbitMessageBatchRouter.kt @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Exactpro (Exactpro Systems Limited) + * Copyright 2022-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -117,6 +117,7 @@ class IntegrationTestRabbitMessageGroupBatchRouter { prefetchCount: Int = DEFAULT_PREFETCH_COUNT, confirmationTimeout: Duration = DEFAULT_CONFIRMATION_TIMEOUT ) = ConnectionManager( + "test-connection", RabbitMQConfiguration( host = rabbitMQContainer.host, vHost = "", diff --git a/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/transport/TransportGroupBatchRouterIntegrationTest.kt b/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/transport/TransportGroupBatchRouterIntegrationTest.kt index 873004c00..119c18c7b 100644 --- a/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/transport/TransportGroupBatchRouterIntegrationTest.kt +++ b/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/transport/TransportGroupBatchRouterIntegrationTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2023 Exactpro (Exactpro Systems Limited) + * Copyright 2023-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -123,6 +123,7 @@ class TransportGroupBatchRouterIntegrationTest { prefetchCount: Int = DEFAULT_PREFETCH_COUNT, confirmationTimeout: Duration = DEFAULT_CONFIRMATION_TIMEOUT ) = ConnectionManager( + "test-connection", RabbitMQConfiguration( host = rabbitMQContainer.host, vHost = "", From 0777b58f243f8defb0fda9eff18c4895a733bc8d Mon Sep 17 00:00:00 2001 From: Oleg Date: Sun, 14 Apr 2024 13:37:40 +0400 Subject: [PATCH 2/4] Increment version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 040f04394..8e330dedd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # -release_version=5.10.0 +release_version=5.10.1 description='th2 common library (Java)' vcs_url=https://github.com/th2-net/th2-common-j kapt.include.compile.classpath=false From b7efac8eb797bcce2981c26c9a3d56ebc5a64df3 Mon Sep 17 00:00:00 2001 From: "nikita.smirnov" Date: Mon, 15 Apr 2024 11:23:34 +0400 Subject: [PATCH 3/4] Bumped version --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 040f04394..c39e24e9a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # -release_version=5.10.0 +release_version=5.10.1 description='th2 common library (Java)' vcs_url=https://github.com/th2-net/th2-common-j -kapt.include.compile.classpath=false +kapt.include.compile.classpath=false \ No newline at end of file From 01eebbb01f23709bd1c440052479b7eb58dfec7f Mon Sep 17 00:00:00 2001 From: "nikita.smirnov" Date: Mon, 15 Apr 2024 16:26:13 +0400 Subject: [PATCH 4/4] Rise `th2_component` metric with box name as `name` label value --- README.md | 7 ++++- .../schema/factory/AbstractCommonFactory.java | 2 ++ .../th2/common/metrics/ComponentMetric.kt | 30 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/com/exactpro/th2/common/metrics/ComponentMetric.kt diff --git a/README.md b/README.md index c12482e6b..f9b0fac24 100644 --- a/README.md +++ b/README.md @@ -433,6 +433,10 @@ NOTES: * some metric labels are enumerations (`th2_type`: `MESSAGE_GROUP`, `EVENT`, ``;`message_type`: `RAW_MESSAGE`, `MESSAGE`) +COMMON METRICS: + +* th2_component (`name`): information about the current component + RABBITMQ METRICS: * th2_rabbitmq_message_size_publish_bytes (`th2_pin`, `th2_type`, `exchange`, `routing_key`): number of published @@ -509,7 +513,8 @@ dependencies { ### 5.10.1-dev -+ Use box name from `box.json` config as RabbitMQ connection name ++ Use box name from `box.json` config as RabbitMQ connection name ++ Rise `th2_component` metric with box name as `name` label value ### 5.10.0-dev diff --git a/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java b/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java index 8545a0def..170920614 100644 --- a/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java +++ b/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java @@ -28,6 +28,7 @@ import com.exactpro.th2.common.grpc.MessageID; import com.exactpro.th2.common.grpc.RawMessageBatch; import com.exactpro.th2.common.metrics.CommonMetrics; +import com.exactpro.th2.common.metrics.ComponentMetric; import com.exactpro.th2.common.metrics.MetricMonitor; import com.exactpro.th2.common.metrics.PrometheusConfiguration; import com.exactpro.th2.common.schema.box.configuration.BoxConfiguration; @@ -187,6 +188,7 @@ public void start() { // init exporter prometheusExporter.getOrNull(); + ComponentMetric.enable(getBoxConfiguration().getBoxName()); livenessMonitor.enable(); } diff --git a/src/main/kotlin/com/exactpro/th2/common/metrics/ComponentMetric.kt b/src/main/kotlin/com/exactpro/th2/common/metrics/ComponentMetric.kt new file mode 100644 index 000000000..4bb20cb4b --- /dev/null +++ b/src/main/kotlin/com/exactpro/th2/common/metrics/ComponentMetric.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2024 Exactpro (Exactpro Systems Limited) + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@file:JvmName("ComponentMetric") + +package com.exactpro.th2.common.metrics + +import io.prometheus.client.Gauge + +private val COMPONENT_METRIC: Gauge = Gauge.build( + "th2_component", + "Information about the current component" +).labelNames("name") + .register() + +internal fun enable(componentName: String) { + COMPONENT_METRIC.labels(componentName).set(1.0) +} \ No newline at end of file