diff --git a/build.gradle.kts b/build.gradle.kts index 3f2b14e..f10d739 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -33,6 +33,44 @@ oci { optionalCredentials() } } + imageMapping { + mapModule("com.hivemq", "hivemq-enterprise") { + toImage("hivemq/hivemq4") + } + } + imageDefinitions { + register("main") { + allPlatforms { + dependencies { + runtime("com.hivemq:hivemq-enterprise:latest") { isChanging = true } + } + layers { + layer("hivemqExtension") { + contents { + permissions("opt/hivemq/", 0b111_111_000) + permissions("opt/hivemq/extensions/", 0b111_111_000) + into("opt/hivemq/extensions") { + filePermissions = 0b110_100_000 // TODO remove, use default + directoryPermissions = 0b111_101_000 // TODO remove, use default + permissions("*/", 0b111_111_000) + permissions("*/dnsdiscovery.properties", 0b110_110_000) + permissions("*/hivemq-extension.xml", 0b110_110_000) + from(zipTree(tasks.hivemqExtensionZip.flatMap { it.archiveFile })) + } + } + } + } + } + } + register("integrationTest") { + allPlatforms { + dependencies { + runtime(project) + runtime("com.hivemq.extensions:hivemq-prometheus-extension") + } + } + } + } } @Suppress("UnstableApiUsage") @@ -61,7 +99,11 @@ testing { } oci.of(this) { imageDependencies { - runtime("hivemq:hivemq4:latest") { isChanging = true } + runtime(project) { + capabilities { + requireCapability("$group:$name-integration-test") // TODO requireFeature("integrationTest"), update gradle to 8.11 + } + }.tag("latest") } } } diff --git a/settings.gradle.kts b/settings.gradle.kts index b58b23b..02803e7 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1 +1,5 @@ rootProject.name = "hivemq-dns-cluster-discovery" + +if (file("../hivemq-prometheus-extension").exists()) { + includeBuild("../hivemq-prometheus-extension") +} diff --git a/src/integrationTest/java/com/hivemq/extensions/cluster/discovery/dns/DnsDiscoveryExtensionIT.java b/src/integrationTest/java/com/hivemq/extensions/cluster/discovery/dns/DnsDiscoveryExtensionIT.java index 719c960..266c3b9 100644 --- a/src/integrationTest/java/com/hivemq/extensions/cluster/discovery/dns/DnsDiscoveryExtensionIT.java +++ b/src/integrationTest/java/com/hivemq/extensions/cluster/discovery/dns/DnsDiscoveryExtensionIT.java @@ -24,14 +24,12 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; -import org.junit.jupiter.api.io.TempDir; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testcontainers.hivemq.HiveMQContainer; +import org.testcontainers.images.builder.Transferable; import org.testcontainers.utility.MountableFile; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.Arrays; import java.util.Map; import java.util.Objects; @@ -61,24 +59,21 @@ class DnsDiscoveryExtensionIT { private @NotNull HiveMQContainer node1; @BeforeEach - void setUp(final @NotNull @TempDir Path extensionTempPath) throws Exception { + void setUp() throws Exception { testDnsServer = new TestDnsServer(Set.of(DNS_DISCOVERY_ADDRESS), 4); testDnsServer.start(); - final Path dnsConfigFile = extensionTempPath.resolve("dnsdiscovery.properties"); - Files.writeString(dnsConfigFile, + final String config = "dnsServerAddress=host.docker.internal:" + testDnsServer.localAddress().getPort() + '\n' + // "discoveryAddress=" + DNS_DISCOVERY_ADDRESS + '\n' + // "resolutionTimeout=30\n" + // - "reloadInterval=60"); + "reloadInterval=60"; - node1 = new HiveMQContainer(OciImages.getImageName("hivemq/hivemq4")) // + node1 = new HiveMQContainer(OciImages.getImageName("hivemq/extensions/hivemq-dns-cluster-discovery") + .asCompatibleSubstituteFor("hivemq/hivemq4")) // .withHiveMQConfig(MountableFile.forClasspathResource("config.xml")) - .withExtension(MountableFile.forClasspathResource("hivemq-dns-cluster-discovery")) - .withFileInExtensionHomeFolder(MountableFile.forHostPath(dnsConfigFile), - "hivemq-dns-cluster-discovery", - "dnsdiscovery.properties") - .withExtension(MountableFile.forClasspathResource("hivemq-prometheus-extension")) + .withCopyToContainer(Transferable.of(config), + "/opt/hivemq/extensions/hivemq-dns-cluster-discovery/dnsdiscovery.properties") .withExposedPorts(9399) .withExtraHost("host.docker.internal", "host-gateway"); } diff --git a/src/integrationTest/resources/hivemq-prometheus-extension/LICENSE.txt b/src/integrationTest/resources/hivemq-prometheus-extension/LICENSE.txt deleted file mode 100644 index 0eec938..0000000 --- a/src/integrationTest/resources/hivemq-prometheus-extension/LICENSE.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2018 dc-square GmbH - - 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. \ No newline at end of file diff --git a/src/integrationTest/resources/hivemq-prometheus-extension/README.adoc b/src/integrationTest/resources/hivemq-prometheus-extension/README.adoc deleted file mode 100644 index 563406f..0000000 --- a/src/integrationTest/resources/hivemq-prometheus-extension/README.adoc +++ /dev/null @@ -1,91 +0,0 @@ -:hivemq-support: http://www.hivemq.com/support/ - -== HiveMQ Prometheus Extension -*Extension Type*: Monitoring - -*Version*: 4.0.3 - -*License*: Apache License 2.0 - -=== Purpose -The Prometheus Monitoring extension allows HiveMQ to expose metrics to a Prometheus application. - -=== Installation - -. Unzip the file: `hivemq-prometheus-extension--distribution.zip` to the directory: `/extensions` -. A configuration file `prometheusConfiguration.properties` can be found in the `hivemq-prometheus-extension` folder. -The properties are preconfigured with standard settings and can be adapted to your needs (The meaning of the fields is explained below). -. Start HiveMQ. - -=== Configuration -The extension can be configured with the `prometheusConfiguration.properties` file, which is part of the `hivemq-prometheus-extension` folder. -[cols="1m,1,2" options="header"] -.Configuration Options -|=== -|Name -|Default -|Description - -|port -|9399 -|The port which the servlet will listen to. - -|host -|0.0.0.0 -|The bind-address which the servlet will listen to. - -|metric_path -|/metrics -|The path for the service which gets called by Prometheus. It must start with a slash. - -|=== - - -=== First Steps -You can test your configuration by navigating to `:` (as configured in `prometheusConfiguration.properties`) in your browser. -For example the address would be http://localhost:9399/metrics with default values. - -You should see data provided by the extension: ----- -# HELP com_hivemq_messages_incoming_publish_rate_total Generated from Dropwizard metric import (metric=com.hivemq.messages.incoming.publish.rate, type=com.codahale.metrics.Meter) -# TYPE com_hivemq_messages_incoming_publish_rate_total counter -com_hivemq_messages_incoming_publish_rate_total 0.0 -... ----- - - -==== Final Steps - -. Load and install Prometheus -. Configure Prometheus to scrape from : as configured in the prometheusConfiguration.properties. -. Look at the website provided by your Prometheus application. You should be able to find the HiveMQ metrics. - -For detailed information please visit: https://prometheus.io/docs/operating/configuration/ - -To enable Prometheus to gather metrics from HiveMQ, you need to add a scrape configuration to your Prometheus configuration. -The following is a minimal example using the default values of the extension: - -.prometheus.yml ----- -global: - scrape_interval: 15s -scrape_configs: - - job_name: 'hivemq' - scrape_interval: 5s - metrics_path: '/metrics' - static_configs: - - targets: ['localhost:9399'] ----- - -==== Need help? - -If you encounter any problems, we are happy to help. The best place to get in contact is our {hivemq-support}[support^]. - -= Contributing - -If you want to contribute to HiveMQ Prometheus Extension, see the link:CONTRIBUTING.adoc[contribution guidelines]. - -= License - -HiveMQ Prometheus Extension is licensed under the `APACHE LICENSE, VERSION 2.0`. A copy of the license can be found link:LICENSE.txt[here]. - diff --git a/src/integrationTest/resources/hivemq-prometheus-extension/README.html b/src/integrationTest/resources/hivemq-prometheus-extension/README.html deleted file mode 100644 index 666888d..0000000 --- a/src/integrationTest/resources/hivemq-prometheus-extension/README.html +++ /dev/null @@ -1,603 +0,0 @@ - - - - - - - -HiveMQ Prometheus Extension - - - - - - -
-
-

HiveMQ Prometheus Extension

-
-
-

Extension Type: Monitoring

-
-
-

Version: 4.0.3

-
-
-

License: Apache License 2.0

-
-
-

Purpose

-
-

The Prometheus Monitoring extension allows HiveMQ to expose metrics to a Prometheus application.

-
-
-
-

Installation

-
-
    -
  1. -

    Unzip the file: hivemq-prometheus-extension-<version>-distribution.zip to the directory: <HIVEMQ_HOME>/extensions

    -
  2. -
  3. -

    A configuration file prometheusConfiguration.properties can be found in the hivemq-prometheus-extension folder. -The properties are preconfigured with standard settings and can be adapted to your needs (The meaning of the fields is explained below).

    -
  4. -
  5. -

    Start HiveMQ.

    -
  6. -
-
-
-
-

Configuration

-
-

The extension can be configured with the prometheusConfiguration.properties file, which is part of the hivemq-prometheus-extension folder.

-
- - ----- - - - - - - - - - - - - - - - - - - - - - - - - -
Table 1. Configuration Options
NameDefaultDescription

port

9399

The port which the servlet will listen to.

host

0.0.0.0

The bind-address which the servlet will listen to.

metric_path

/metrics

The path for the service which gets called by Prometheus. It must start with a slash.

-
-
-

First Steps

-
-

You can test your configuration by navigating to <ip>:<port><metric_path> (as configured in prometheusConfiguration.properties) in your browser. -For example the address would be http://localhost:9399/metrics with default values.

-
-
-

You should see data provided by the extension:

-
-
-
-
# HELP com_hivemq_messages_incoming_publish_rate_total Generated from Dropwizard metric import (metric=com.hivemq.messages.incoming.publish.rate, type=com.codahale.metrics.Meter)
-# TYPE com_hivemq_messages_incoming_publish_rate_total counter
-com_hivemq_messages_incoming_publish_rate_total 0.0
-...
-
-
-
-

Final Steps

-
-
    -
  1. -

    Load and install Prometheus

    -
  2. -
  3. -

    Configure Prometheus to scrape from <ip>:<port><metricPath> as configured in the prometheusConfiguration.properties.

    -
  4. -
  5. -

    Look at the website provided by your Prometheus application. You should be able to find the HiveMQ metrics.

    -
  6. -
-
-
-

For detailed information please visit: https://prometheus.io/docs/operating/configuration/

-
-
-

To enable Prometheus to gather metrics from HiveMQ, you need to add a scrape configuration to your Prometheus configuration. -The following is a minimal example using the default values of the extension:

-
-
-
prometheus.yml
-
-
global:
-  scrape_interval: 15s
-scrape_configs:
-  - job_name: 'hivemq'
-    scrape_interval: 5s
-    metrics_path: '/metrics'
-    static_configs:
-      - targets: ['localhost:9399']
-
-
-
-
-

Need help?

-
-

If you encounter any problems, we are happy to help. The best place to get in contact is our support.

-
-
-
-
-
-

Contributing

-
-

If you want to contribute to HiveMQ Prometheus Extension, see the contribution guidelines.

-
-

License

-
-

HiveMQ Prometheus Extension is licensed under the APACHE LICENSE, VERSION 2.0. A copy of the license can be found here.

-
-
- - - \ No newline at end of file diff --git a/src/integrationTest/resources/hivemq-prometheus-extension/hivemq-extension.xml b/src/integrationTest/resources/hivemq-prometheus-extension/hivemq-extension.xml deleted file mode 100644 index e078b14..0000000 --- a/src/integrationTest/resources/hivemq-prometheus-extension/hivemq-extension.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - hivemq-prometheus-extension - Prometheus Monitoring Extension - 4.0.3 - 1000 - dc-square GmbH - diff --git a/src/integrationTest/resources/hivemq-prometheus-extension/hivemq-prometheus-extension-4.0.3.jar b/src/integrationTest/resources/hivemq-prometheus-extension/hivemq-prometheus-extension-4.0.3.jar deleted file mode 100644 index 836b77d..0000000 Binary files a/src/integrationTest/resources/hivemq-prometheus-extension/hivemq-prometheus-extension-4.0.3.jar and /dev/null differ diff --git a/src/integrationTest/resources/hivemq-prometheus-extension/prometheusConfiguration.properties b/src/integrationTest/resources/hivemq-prometheus-extension/prometheusConfiguration.properties deleted file mode 100644 index d426e3e..0000000 --- a/src/integrationTest/resources/hivemq-prometheus-extension/prometheusConfiguration.properties +++ /dev/null @@ -1,30 +0,0 @@ -# ------------------------------------------------------------------------- -# -# _ _ _ __ __ ____ -# | | | |(_) | \/ | / __ \ -# | |__| | _ __ __ ___ | \ / || | | | -# | __ || |\ \ / // _ \| |\/| || | | | -# | | | || | \ V /| __/| | | || |__| | -# |_| |_||_| \_/ \___||_| |_| \___\_\ -# -# ------------------------------------------------------------------------- -# -# Prometheus Monitoring Extension Configuration -# -# ------------------------------------------------------------------------- - - -# The ip where the servlet will be hosted -ip=0.0.0.0 - -# The port where the servlet will work on -port=9399 - -# The path for the servlet which gets called by prometheus -# : and -# For example 127.0.0.1:9399/metrics -metric_path=/metrics - - - -