Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose metrics via Control #338

Merged
merged 3 commits into from
Apr 3, 2018
Merged

Expose metrics via Control #338

merged 3 commits into from
Apr 3, 2018

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented Sep 7, 2017

We'd like to be able to expose metrics to users when they use the Sharing the Consumer Actor pattern; I thought this style would likely be good enough - I assume the same could be done in the Publisher?

@ktoso
Copy link
Contributor Author

ktoso commented Sep 8, 2017

Please review is this general idea could make it in @patriknw @kciesielski @13h3r :)

@13h3r
Copy link
Contributor

13h3r commented Sep 8, 2017

Yes, I think it could be implemented this way

@kciesielski
Copy link
Contributor

Thanks, LGTM. As for producer, there's Producer.flow(settings: ProducerSettings, producer: KafkaProducer), so users can provide their own producers which can be directly asked for metrics.

@ktoso
Copy link
Contributor Author

ktoso commented Sep 10, 2017 via email

Copy link
Member

@patriknw patriknw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor api adjustments, otherwise good

/** Public protocol which can be used to interact with the Actor */
object Protocol {
// requests
final case class RequestMetrics()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strange with case class without params, case object?

then it need accessor for Java API

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


// responses
/** Contains a snapshot of metrics obtained from the underlying kafka consumer */
final case class ConsumerMetrics(metrics: Map[MetricName, Metric])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java API: getMetrics: java.util.Map

@v-gerasimov
Copy link

What about this PR? Seems there is no way to get consumer metrics now.

@ktoso
Copy link
Contributor Author

ktoso commented Mar 26, 2018

Hah, got reminded of this one via discuss.akka.io Will fix it

@ktoso ktoso force-pushed the wip-expose-metrics branch from 2a1eb86 to a36a736 Compare March 26, 2018 07:23
@ktoso
Copy link
Contributor Author

ktoso commented Mar 26, 2018

Addressed feedback, checked Java API, added docs (also for producer where it's trivial however added it so it's all explained symmetrically).

Please review @kciesielski @patriknw

override def onPartitionsRevoked(partitions: util.Collection[TopicPartition]): Unit = {
onRevoke(partitions.asScala)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this have to do with metrics?

Copy link
Contributor Author

@ktoso ktoso Mar 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase gone weird :\ Thanks

/** Java API */
def getMetrics: util.Map[MetricName, Metric] = metrics.asJava
}
// ------------ end of public protocol ------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works when the KafkaConsumer actor is created and passed in, but what about the other cases where the actor is created by the library? Wouldn't it be better to expose the metrics via the Control materialized value?

Could be a Future and using ask internally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good point, will add that

@ktoso
Copy link
Contributor Author

ktoso commented Mar 26, 2018

Yeah you're right that a def metrics on the Control should be added as well; will do so

@johanandren johanandren mentioned this pull request Mar 26, 2018
@patriknw
Copy link
Member

Perhaps Control can be the only public API?

@ktoso ktoso changed the title Idea on exposing metrics Expose metrics via Control Mar 27, 2018
@ktoso
Copy link
Contributor Author

ktoso commented Mar 27, 2018

Perhaps Control can be the only public API?

Yeah, tried doing that. It's hard to make it def metrics: Map[MetricName, Metric] sadly, due to the SubSourceLogic and friends... This would be optimal API for users.

It is easier to make it a Future[Map which probably is good enough

@ktoso
Copy link
Contributor Author

ktoso commented Mar 27, 2018

Done, now the only API is to get metrics from the control value

@ktoso
Copy link
Contributor Author

ktoso commented Mar 27, 2018

Please give it a look @patriknw when you have some time

Copy link
Contributor

@chbatey chbatey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. LGTM with a few import cleanups which we should automate :)

import org.apache.kafka.clients.consumer.ConsumerRecord
import org.apache.kafka.common.TopicPartition
import akka.util.Timeout
import org.apache.kafka.clients.consumer.{Consumer, ConsumerRecord}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consumer is unused

@@ -9,6 +9,8 @@ import java.util.concurrent.TimeUnit

import akka.NotUsed
import akka.actor.{ActorRef, ExtendedActorSystem, Terminated}
import akka.dispatch.ExecutionContexts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean up imports, some of the new unused

@@ -7,20 +7,23 @@ package sample.scaladsl
import akka.pattern.ask
import akka.kafka.ConsumerMessage.{CommittableMessage, CommittableOffsetBatch}
import akka.kafka._
import akka.actor.{Props, ActorRef, Actor, ActorSystem, ActorLogging, PoisonPill}
import akka.actor.{Actor, ActorLogging, ActorRef, ActorSystem, PoisonPill, Props}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these new imports are unused

@@ -187,6 +192,11 @@ private[kafka] class KafkaConsumerActor[K, V](settings: ConsumerSettings[K, V])
stopInProgress = true
context.become(stopping)
}

case RequestMetrics =>
val unmodifiableYetMutableMetrics: java.util.Map[MetricName, _ <: Metric] = consumer.metrics()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This map goes through a lot of conversions for the Java case.

I guess there's no point trying to avoid this. Looking at the Kafka code they give us the raw map wrapped in an unmodifiable so we shouldn't pass that around.

Copy link
Contributor Author

@ktoso ktoso Apr 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it is converted a lot indeed... I figured to leave it along until or rather IF reported as a problem

Copy link
Member

@patriknw patriknw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ktoso
Copy link
Contributor Author

ktoso commented Apr 3, 2018

Thanks! Exciting one :)

@ktoso ktoso merged commit be43b58 into master Apr 3, 2018
@ktoso ktoso deleted the wip-expose-metrics branch April 3, 2018 06:35
@ktoso ktoso added this to the 0.20 milestone Apr 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants