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

Filter topics by committer #13

Merged

Conversation

bharathi-ravishanker
Copy link
Contributor

No description provided.

@bharathi-ravishanker
Copy link
Contributor Author

bharathi-ravishanker commented Jul 8, 2017

Initial commit without tests @denisgrenader

Copy link
Contributor

@denisgrenader denisgrenader left a comment

Choose a reason for hiding this comment

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

Mostly name changes, and one logical comment

@@ -44,6 +44,11 @@ class Castle private (val castleConfig: CastleConfig, val metricsLogger: Metrics
}
}).toMap

val filterMap: Map[String, Filter] = committerFactoryMap map {
idCommitterFactory => {
Copy link
Contributor

Choose a reason for hiding this comment

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

idCommitterFactoryPair => {

@@ -44,6 +44,11 @@ class Castle private (val castleConfig: CastleConfig, val metricsLogger: Metrics
}
}).toMap

val filterMap: Map[String, Filter] = committerFactoryMap map {
idCommitterFactory => {
idCommitterFactory._1 -> idCommitterFactory._2.createFilter()
Copy link
Contributor

Choose a reason for hiding this comment

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

idCommitterFactoryPair._1 -> idCommitterFactoryPair._2.createTopicFilter()

@@ -44,6 +44,11 @@ class Castle private (val castleConfig: CastleConfig, val metricsLogger: Metrics
}
}).toMap

val filterMap: Map[String, Filter] = committerFactoryMap map {
Copy link
Contributor

Choose a reason for hiding this comment

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

topicFilterMap: Map[String, TopicFilter] = committerFactoryMap map {

@@ -84,7 +89,7 @@ class Castle private (val castleConfig: CastleConfig, val metricsLogger: Metrics

val workerActorFactory = new WorkerActorFactory(fetcherActorFactory, workerFactory, castleConfig.committerConfigs, metricsLogger)

val taskManager = TaskManager(castleConfig.leaderConfig, castleConfig.committerConfigs)
val taskManager = TaskManager(castleConfig.leaderConfig, castleConfig.committerConfigs, filterMap)
Copy link
Contributor

Choose a reason for hiding this comment

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

, topicFilterMap)

def apply(
leaderConfig: LeaderConfig,
committerConfigs: Iterable[CommitterConfig],
committerFilterMap: Map[String, Filter]) =
Copy link
Contributor

Choose a reason for hiding this comment

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

topicFilterMap: Map[String, TopicFilter]) =

class TaskManager(
val leaderConfig: LeaderConfig,
val committerConfigs: Iterable[CommitterConfig],
committerFilterMap: Map[String, Filter]) extends Logging {
Copy link
Contributor

Choose a reason for hiding this comment

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

topicFilterMap: Map[String, TopicFilter]) extends Logging {

private def matchCommitterFilter(kafkaTopic: KafkaTopic, committerId: String): Boolean = {
val filter = committerFilterMap(committerId)
filter.containsTopic(kafkaTopic.name)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

val topicFilter = topicFilterMap(committerId)
topicFilter.match(kafkaTopic.name)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

match is a keyword in scala and wont let me use it

committerIds + committerId
else
committerIds
}

private def matchCommitterFilter(kafkaTopic: KafkaTopic, committerId: String): Boolean = {
Copy link
Contributor

Choose a reason for hiding this comment

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

private def matchCommitterTopicFilter

}
}
else {
committerIds
Copy link
Contributor

Choose a reason for hiding this comment

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

regex match is more stable and well known than whatever the committer filter does, let's invert their checking:

private def matchTopicsRegex(topicsRegex: Regex, kafkaTopic: KafkaTopic, committerId: String, committerIds: Set[String]): Set[String] = {
    kafkaTopic.name match {
      case topicsRegex(_*) => if (matchCommitterTopicFilter(kafkaTopic, committerId)) committerIds + committerId else committerIds
      case _ => committerIds
    }
  }

@bharathi-ravishanker bharathi-ravishanker dismissed denisgrenader’s stale review July 11, 2017 23:44

Added comments in the commit. Merging this for now and open to more comments

taskManager.matchTopicsSet(Set("performance", "login"),performanceTopic,"falseCommitter", Set("kafkaCommitter")) shouldEqual Set("kafkaCommitter")
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

can you add one more test
where the there is a "split" acceptance committer
on some topics
where it accepts some but not others
i.e. if the topics to subscribe are Foo, Bar, Baz
the topic regex is “.*”
so all match
but then the committer returns “true” for Foo,
but “false” for Bar, Baz
right now this case does not cover the split it doesn’t cover the split case

the same thing goes for TopicSet

def apply(
leaderConfig: LeaderConfig,
committerConfigs: Iterable[CommitterConfig],
topicFilterMap: Map[String, TopicFilter]) =
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this always be required? If not, would it make sense to provide a default parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Every commiterFactory has a TopicFilter associated with it. It should be mandatory

}
protected[leader] def matchTopicsRegex(topicsRegex: Regex, kafkaTopic: KafkaTopic, committerId: String, committerIds: Set[String]) = {
kafkaTopic.name match {
case topicsRegex(_*) => if(matchCommitterTopicFilter(kafkaTopic,committerId)) committerIds + committerId else committerIds
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Space between if & open paren ("(")
  2. Since we have 2 conditions, would it make sense to change this to a simple if-statement, rather than using case and then a nested If? (See matchTopicsSet(...) -- It seems the logic is quite similar, except the topicsSet(...) versus topicsRegex(...))

case topicsRegex(_*) => committerIds + committerId
case _ => committerIds
}
protected[leader] def matchTopicsRegex(topicsRegex: Regex, kafkaTopic: KafkaTopic, committerId: String, committerIds: Set[String]) = {
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Need a function signature
  2. What's the difference between committerId & committerIds?

committerIds + committerId
else
committerIds
}

protected[leader] def matchCommitterTopicFilter(kafkaTopic: KafkaTopic, committerId: String): Boolean = {
Copy link
Contributor

@dashk dashk Jul 11, 2017

Choose a reason for hiding this comment

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

  1. It might be good to make function behavior consistent -- matchTopicsSet(...) returns a Set[String], while matchCommitterTopicFilter returns a Boolean.
  2. Function signature 😄

import com.box.castle.committer.api.TopicFilter

/**
* Created by bravishanker on 7/10/17.
Copy link
Contributor

Choose a reason for hiding this comment

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

Update class description

}

private def matchTopicsSet(topicsSet: Set[String], kafkaTopic: KafkaTopic, committerId: String, committerIds: Set[String]) = {
if (topicsSet.contains(kafkaTopic.name))
protected[leader] def matchTopicsSet(topicsSet: Set[String], kafkaTopic: KafkaTopic, committerId: String, committerIds: Set[String]) = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add function description.

}



class TaskManager(val leaderConfig: LeaderConfig, val committerConfigs: Iterable[CommitterConfig]) extends Logging {
class TaskManager(
Copy link
Contributor

Choose a reason for hiding this comment

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

Need class description

@bharathi-ravishanker bharathi-ravishanker merged commit 05a6241 into Box-Castle:master Jul 12, 2017
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.

None yet

4 participants