From fc9f2707f17c8548d8d58cc91cdb491dde9c5215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Andr=C3=A9n?= Date: Thu, 18 Jan 2024 15:40:26 +0100 Subject: [PATCH] chore: Drop unmaintained Consul discovery module --- README.md | 1 - build.sbt | 12 -- .../src/main/resources/reference.conf | 25 ---- .../consul/ConsulServiceDiscovery.scala | 121 ------------------ .../discovery/consul/ConsulSettings.scala | 33 ----- .../discovery/ConsulDiscoverySpec.scala | 81 ------------ docs/src/main/paradox/discovery/consul.md | 81 +----------- docs/src/main/paradox/discovery/index.md | 3 +- docs/src/main/paradox/index.md | 1 - .../management/scaladsl/AkkaManagement.scala | 1 - project/Dependencies.scala | 18 --- project/project-info.conf | 10 -- 12 files changed, 3 insertions(+), 384 deletions(-) delete mode 100644 discovery-consul/src/main/resources/reference.conf delete mode 100644 discovery-consul/src/main/scala/akka/discovery/consul/ConsulServiceDiscovery.scala delete mode 100644 discovery-consul/src/main/scala/akka/discovery/consul/ConsulSettings.scala delete mode 100644 discovery-consul/src/test/scala/akka/cluster/bootstrap/discovery/ConsulDiscoverySpec.scala diff --git a/README.md b/README.md index c81c5844d..2b1b231d6 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,6 @@ for the following modules. * akka-discovery-marathon-api * akka-discovery-aws-api * akka-discovery-aws-api-async -* akka-discovery-consul diff --git a/build.sbt b/build.sbt index 9159ddd11..0066e56d0 100644 --- a/build.sbt +++ b/build.sbt @@ -19,7 +19,6 @@ lazy val `akka-management-root` = project // in AkkaManagement should also be updated `akka-discovery-aws-api`, `akka-discovery-aws-api-async`, - `akka-discovery-consul`, `akka-discovery-kubernetes-api`, `akka-discovery-marathon-api`, `akka-management`, @@ -97,17 +96,6 @@ lazy val `akka-discovery-aws-api-async` = project mimaPreviousArtifactsSet ) -lazy val `akka-discovery-consul` = project - .in(file("discovery-consul")) - .enablePlugins(AutomateHeaderPlugin) - .disablePlugins(com.geirsson.CiReleasePlugin) - .settings( - name := "akka-discovery-consul", - organization := "com.lightbend.akka.discovery", - libraryDependencies := Dependencies.DiscoveryConsul, - mimaPreviousArtifactsSet - ) - // gathers all enabled routes and serves them (HTTP or otherwise) lazy val `akka-management` = project .in(file("management")) diff --git a/discovery-consul/src/main/resources/reference.conf b/discovery-consul/src/main/resources/reference.conf deleted file mode 100644 index d60c896ef..000000000 --- a/discovery-consul/src/main/resources/reference.conf +++ /dev/null @@ -1,25 +0,0 @@ -###################################################### -# Akka Service Discovery Consul Config # -###################################################### - -akka.discovery { - - # Set the following in your application.conf if you want to use this discovery mechanism: - # impl = akka-consul - # ApiMayChange - akka-consul { - class = akka.discovery.consul.ConsulServiceDiscovery - - consul-host = "127.0.0.1" - consul-port = 8500 - - # Prefix for consul tag with the name of the actor system / application name, - # services with this tag present will be found by the discovery mechanism - # i.e. `system:test` will be found in cluster if the cluster system is named `test` - application-name-tag-prefix = "system:" - - # Prefix for tag containing port number where akka management is set up so that - # the seed nodes can be found, an example value for the tag would be `akka-management-port:19999` - application-akka-management-port-tag-prefix = "akka-management-port:" - } -} diff --git a/discovery-consul/src/main/scala/akka/discovery/consul/ConsulServiceDiscovery.scala b/discovery-consul/src/main/scala/akka/discovery/consul/ConsulServiceDiscovery.scala deleted file mode 100644 index c5d8d171d..000000000 --- a/discovery-consul/src/main/scala/akka/discovery/consul/ConsulServiceDiscovery.scala +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2017-2023 Lightbend Inc. - */ - -package akka.discovery.consul - -import java.net.InetAddress -import java.util -import java.util.concurrent.TimeoutException - -import akka.actor.ActorSystem -import scala.collection.immutable.Seq -import scala.concurrent.{ ExecutionContext, Future, Promise } - -import akka.pattern.after -import com.google.common.net.HostAndPort -import com.orbitz.consul.Consul -import com.orbitz.consul.async.ConsulResponseCallback -import com.orbitz.consul.model.ConsulResponse -import ConsulServiceDiscovery._ -import akka.discovery.ServiceDiscovery.{ Resolved, ResolvedTarget } -import akka.discovery.{ Lookup, ServiceDiscovery } -import com.orbitz.consul.model.catalog.CatalogService -import com.orbitz.consul.option.QueryOptions -import scala.collection.JavaConverters._ -import scala.concurrent.duration.FiniteDuration -import scala.util.Try - -import akka.annotation.ApiMayChange - -@ApiMayChange -class ConsulServiceDiscovery(system: ActorSystem) extends ServiceDiscovery { - - private val settings = ConsulSettings.get(system) - private val consul = - Consul.builder().withHostAndPort(HostAndPort.fromParts(settings.consulHost, settings.consulPort)).build() - - override def lookup(lookup: Lookup, resolveTimeout: FiniteDuration): Future[Resolved] = { - implicit val ec: ExecutionContext = system.dispatcher - Future.firstCompletedOf( - Seq( - after(resolveTimeout, using = system.scheduler)( - Future.failed(new TimeoutException(s"Lookup for [${lookup}] timed-out, within [${resolveTimeout}]!")) - ), - lookupInConsul(lookup.serviceName) - ) - ) - } - - private def lookupInConsul(name: String)(implicit executionContext: ExecutionContext): Future[Resolved] = { - val consulResult = for { - servicesWithTags <- getServicesWithTags - serviceIds = servicesWithTags.getResponse - .entrySet() - .asScala - .filter(e => e.getValue.contains(settings.applicationNameTagPrefix + name)) - .map(_.getKey) - catalogServices <- Future.sequence(serviceIds.map(id => getService(id).map(_.getResponse.asScala.toList))) - resolvedTargets = catalogServices.flatten.toSeq.map(catalogService => - extractResolvedTargetFromCatalogService(catalogService)) - } yield resolvedTargets - consulResult.map(targets => Resolved(name, scala.collection.immutable.Seq(targets: _*))) - } - - private def extractResolvedTargetFromCatalogService(catalogService: CatalogService) = { - val port = catalogService.getServiceTags.asScala - .find(_.startsWith(settings.applicationAkkaManagementPortTagPrefix)) - .map(_.replace(settings.applicationAkkaManagementPortTagPrefix, "")) - .flatMap { maybePort => - Try(maybePort.toInt).toOption - } - val address = catalogService.getServiceAddress - ResolvedTarget( - host = address, - port = Some(port.getOrElse(catalogService.getServicePort)), - address = Try(InetAddress.getByName(address)).toOption - ) - } - - private def getServicesWithTags: Future[ConsulResponse[util.Map[String, util.List[String]]]] = { - ((callback: ConsulResponseCallback[util.Map[String, util.List[String]]]) => - consul.catalogClient().getServices(callback)).asFuture - } - - private def getService(name: String) = - ((callback: ConsulResponseCallback[util.List[CatalogService]]) => - consul.catalogClient().getService(name, QueryOptions.BLANK, callback)).asFuture - -} - -@ApiMayChange -object ConsulServiceDiscovery { - - implicit class ConsulResponseFutureDecorator[T](f: ConsulResponseCallback[T] => Unit) { - def asFuture: Future[ConsulResponse[T]] = { - val callback = new ConsulResponseFutureCallback[T] - Try(f(callback)).recover[Unit] { - case ex: Throwable => callback.fail(ex) - } - callback.future - } - } - - final case class ConsulResponseFutureCallback[T]() extends ConsulResponseCallback[T] { - - private val promise = Promise[ConsulResponse[T]] - - def fail(exception: Throwable) = promise.failure(exception) - - def future: Future[ConsulResponse[T]] = promise.future - - override def onComplete(consulResponse: ConsulResponse[T]): Unit = { - promise.success(consulResponse) - } - - override def onFailure(throwable: Throwable): Unit = { - promise.failure(throwable) - } - } - -} diff --git a/discovery-consul/src/main/scala/akka/discovery/consul/ConsulSettings.scala b/discovery-consul/src/main/scala/akka/discovery/consul/ConsulSettings.scala deleted file mode 100644 index 53ff36a37..000000000 --- a/discovery-consul/src/main/scala/akka/discovery/consul/ConsulSettings.scala +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2017-2023 Lightbend Inc. - */ - -package akka.discovery.consul - -import akka.actor.ClassicActorSystemProvider -import akka.actor.{ ActorSystem, ExtendedActorSystem, Extension, ExtensionId, ExtensionIdProvider } -import akka.annotation.ApiMayChange - -@ApiMayChange -final class ConsulSettings(system: ExtendedActorSystem) extends Extension { - private val consulConfig = system.settings.config.getConfig("akka.discovery.akka-consul") - - val consulHost: String = consulConfig.getString("consul-host") - - val consulPort: Int = consulConfig.getInt("consul-port") - - val applicationNameTagPrefix: String = consulConfig.getString("application-name-tag-prefix") - val applicationAkkaManagementPortTagPrefix: String = - consulConfig.getString("application-akka-management-port-tag-prefix") -} - -@ApiMayChange -object ConsulSettings extends ExtensionId[ConsulSettings] with ExtensionIdProvider { - override def get(system: ActorSystem): ConsulSettings = super.get(system) - - override def get(system: ClassicActorSystemProvider): ConsulSettings = super.get(system) - - override def lookup: ConsulSettings.type = ConsulSettings - - override def createExtension(system: ExtendedActorSystem): ConsulSettings = new ConsulSettings(system) -} diff --git a/discovery-consul/src/test/scala/akka/cluster/bootstrap/discovery/ConsulDiscoverySpec.scala b/discovery-consul/src/test/scala/akka/cluster/bootstrap/discovery/ConsulDiscoverySpec.scala deleted file mode 100644 index 65add3837..000000000 --- a/discovery-consul/src/test/scala/akka/cluster/bootstrap/discovery/ConsulDiscoverySpec.scala +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2017-2023 Lightbend Inc. - */ - -package akka.cluster.bootstrap.discovery - -import java.net.InetAddress - -import akka.actor.ActorSystem -import akka.discovery.ServiceDiscovery.ResolvedTarget -import akka.discovery.consul.ConsulServiceDiscovery -import akka.testkit.TestKitBase -import com.google.common.net.HostAndPort -import com.orbitz.consul.Consul -import com.orbitz.consul.model.catalog.ImmutableCatalogRegistration -import com.orbitz.consul.model.health.ImmutableService -import com.pszymczyk.consul.{ ConsulProcess, ConsulStarterBuilder } -import org.scalatest.concurrent.ScalaFutures -import org.scalatest.time.{ Millis, Seconds, Span } -import org.scalatest.BeforeAndAfterAll - -import scala.concurrent.duration._ -import org.scalatest.matchers.should.Matchers -import org.scalatest.wordspec.AnyWordSpecLike - -class ConsulDiscoverySpec - extends AnyWordSpecLike - with Matchers - with BeforeAndAfterAll - with TestKitBase - with ScalaFutures { - - private val consul: ConsulProcess = ConsulStarterBuilder.consulStarter().withHttpPort(8500).build().start() - - "Consul Discovery" should { - "work for defaults" in { - val consulAgent = - Consul.builder().withHostAndPort(HostAndPort.fromParts(consul.getAddress, consul.getHttpPort)).build() - consulAgent - .catalogClient() - .register( - ImmutableCatalogRegistration - .builder() - .service( - ImmutableService - .builder() - .addTags(s"system:${system.name}", "akka-management-port:1234") - .address("127.0.0.1") - .id("test") - .service("test") - .port(1235) - .build() - ) - .node("testNode") - .address("localhost") - .build() - ) - - val lookupService = new ConsulServiceDiscovery(system) - val resolved = lookupService.lookup("test", 10.seconds).futureValue - resolved.addresses should contain( - ResolvedTarget( - host = "127.0.0.1", - port = Some(1234), - address = Some(InetAddress.getByName("127.0.0.1")) - ) - ) - } - } - - override def afterAll(): Unit = { - super.afterAll() - consul.close() - } - - override implicit lazy val system: ActorSystem = ActorSystem("test") - - implicit override val patienceConfig: PatienceConfig = - PatienceConfig(timeout = scaled(Span(30, Seconds)), interval = scaled(Span(50, Millis))) - -} diff --git a/docs/src/main/paradox/discovery/consul.md b/docs/src/main/paradox/discovery/consul.md index 008c1f014..1c0e1d6fe 100644 --- a/docs/src/main/paradox/discovery/consul.md +++ b/docs/src/main/paradox/discovery/consul.md @@ -1,81 +1,4 @@ ## Consul -@@@ warning - -This module is community maintained and the Lightbend subscription doesn't cover support for this module. - It is also marked as @extref:[may change](akka:common/may-change.html). - That means that the API, configuration or semantics can change without warning or deprecation period. - -@@@ - -Consul currently ignores all fields apart from service name. This is expected to change. - -If you are using Consul to do the service discovery this would allow you to base your Cluster on Consul services. - -## Project Info - -@@project-info{ projectId="akka-discovery-consul" } - -The Akka dependencies are available from Akka's library repository. To access them there, you need to configure the URL for this repository. - -@@repository [sbt,Gradle,Maven] { -id="akka-repository" -name="Akka library repository" -url="https://repo.akka.io/maven" -} - -Additionally, add the dependency as below. - -@@dependency[sbt,Gradle,Maven] { - symbol1=AkkaManagementVersion - value1=$project.version$ - group="com.lightbend.akka.discovery" - artifact="akka-discovery-consul_$scala.binary.version$" - version=AkkaManagementVersion -} - -`akka-discovery-consul` can be used with Akka $akka.version$ or later. -You have to override the following Akka dependencies by defining them explicitly in your build and -define the Akka version to the one that you are using. Latest patch version of Akka is recommended and -a later version than $akka.version$ can be used. - -@@dependency[sbt,Gradle,Maven] { - symbol=AkkaVersion - value=$akka.version$ - group=com.typesafe.akka - artifact=akka-cluster_$scala.binary.version$ - version=AkkaVersion - group2=com.typesafe.akka - artifact2=akka-discovery_$scala.binary.version$ - version2=AkkaVersion -} - -In your application conf add: -``` -akka.discovery { - method = akka-consul - akka-consul { - - #How to connect to Consul to fetch services data - consul-host = "127.0.0.1" - consul-port = 8500 - - # Prefix for consul tag with the name of the actor system / application name, - # services with this tag present will be found by the discovery mechanism - # i.e. `system:test` will be found in cluster if the cluster system is named `test` - application-name-tag-prefix = "system:" - - # Prefix for tag containing port number where akka management is set up so that - # the seed nodes can be found, an example value for the tag would be `akka-management-port:19999` - application-akka-management-port-tag-prefix = "akka-management-port:" - } -} -``` - -Notes: - -* Since tags in Consul services are simple strings, prefixes are necessary to ensure that proper values are read. - -* If Akka management port tag is not found on service in Consul the implementation defaults to catalog service port. - - +The akka-discovery-consul module had upstream security issues and was not maintained, it has therefore been dropped +from Akka Management. The last published version of this module was with Akka Management 1.5.0. diff --git a/docs/src/main/paradox/discovery/index.md b/docs/src/main/paradox/discovery/index.md index 9900249ac..badfc63b4 100644 --- a/docs/src/main/paradox/discovery/index.md +++ b/docs/src/main/paradox/discovery/index.md @@ -7,7 +7,6 @@ Akka Discovery module in Akka. Akka Management contains methods for: * @ref[Kubernetes](kubernetes.md) - * @ref[Consul](consul.md) * @ref[Marathon](marathon.md) * @ref[AWS](aws.md) @@ -18,8 +17,8 @@ part of the build and release process. @@@ index - [Kubernetes](kubernetes.md) - - [Consul](consul.md) - [Marathon](marathon.md) - [AWS](aws.md) + - [Consul (discontinued)](consul.md) @@@ diff --git a/docs/src/main/paradox/index.md b/docs/src/main/paradox/index.md index 2eedda9ac..8b3f9fbae 100644 --- a/docs/src/main/paradox/index.md +++ b/docs/src/main/paradox/index.md @@ -16,7 +16,6 @@ Akka Management consists of multiple modules: As well as @extref:[Akka Discovery](akka:discovery/index.html) methods for: * @ref[Kubernetes API](discovery/kubernetes.md) - * @ref[Consul](discovery/consul.md) * @ref[Marathon API](discovery/marathon.md) * @ref[AWS](discovery/aws.md) diff --git a/management/src/main/scala/akka/management/scaladsl/AkkaManagement.scala b/management/src/main/scala/akka/management/scaladsl/AkkaManagement.scala index 02c58da17..4081f388c 100644 --- a/management/src/main/scala/akka/management/scaladsl/AkkaManagement.scala +++ b/management/src/main/scala/akka/management/scaladsl/AkkaManagement.scala @@ -58,7 +58,6 @@ final class AkkaManagement(implicit private[akka] val system: ExtendedActorSyste ManifestInfo(system).checkSameVersion( productName = "Akka Management", dependencies = List( - "akka-discovery-consul", "akka-discovery-aws-api", "akka-discovery-marathon-api", "akka-discovery-aws-api-async", diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 456fb5b7f..60a84925c 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -28,24 +28,6 @@ object Dependencies { "com.fasterxml.jackson.core" % "jackson-databind" % JacksonDatabindVersion ) - private val JacksonDatatype = Seq( - "com.fasterxml.jackson.datatype" % "jackson-datatype-guava" % JacksonVersion, - "com.fasterxml.jackson.datatype" % "jackson-datatype-jdk8" % JacksonVersion, - // Specifying guava dependency because older transitive dependency has security vulnerability - "com.google.guava" % "guava" % "32.1.3-jre" - ) - - val DiscoveryConsul = Seq( - "com.typesafe.akka" %% "akka-actor" % AkkaVersion, - "com.typesafe.akka" %% "akka-discovery" % AkkaVersion, - "com.orbitz.consul" % "consul-client" % "1.5.3", - "com.pszymczyk.consul" % "embedded-consul" % "2.2.1" % Test, - "org.scalatest" %% "scalatest" % ScalaTestVersion % Test, - "com.typesafe.akka" %% "akka-testkit" % AkkaVersion % Test, - "com.typesafe.akka" %% "akka-slf4j" % AkkaVersion % Test, - "ch.qos.logback" % "logback-classic" % "1.2.13" % Test - ) ++ JacksonDatabind ++ JacksonDatatype // consul depends on insecure version of jackson - val DiscoveryKubernetesApi = Seq( "com.typesafe.akka" %% "akka-actor" % AkkaVersion, "com.typesafe.akka" %% "akka-discovery" % AkkaVersion, diff --git a/project/project-info.conf b/project/project-info.conf index 9580e1846..445bb44ce 100644 --- a/project/project-info.conf +++ b/project/project-info.conf @@ -72,16 +72,6 @@ project-info { } ] } - akka-discovery-consul: ${project-info.shared-info} { - title: "Akka Discovery Consul" - levels: [ - { // keep in sync with README.md - readiness: CommunityDriven - since: "2018-07-02" - since-version: "0.15.0" - } - ] - } akka-discovery-marathon-api: ${project-info.shared-info} { title: "Akka Discovery Marathon" levels: [