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

Allow Apache Kafka scaler to scale using sum of lag for all topics within a consumer group #2409

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update e2e test
Signed-off-by: Jinli Liang <paul.liang@rokt.com>
  • Loading branch information
PaulLiang1 committed Jan 11, 2022
commit 41d7ad23fb415e753fabed84ab596ce8045f21b7
31 changes: 22 additions & 9 deletions tests/scalers/kafka.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,33 @@ test.serial('Applying ScaledObject with multiple topics should scale up pods', t
'Deploying Scaled Object should work.'
)
sh.exec(`sleep 5s`)
waitForReplicaCount(1, commandToCheckReplicas)
t.is('0', sh.exec(commandToCheckReplicas).stdout, 'Replica count should be 0.')

// produce a single msg to the default topic should not scale
sh.exec(`kubectl exec --namespace ${defaultNamespace} ${defaultKafkaClient} -- sh -exc 'echo "{\"text\": \"foo\"}" | kafka-console-producer --broker-list ${defaultCluster}-kafka-bootstrap.${defaultNamespace}:9092 --topic ${defaultTopic}'`)
sh.exec(`sleep 20s`)
// when lag is 0, scaled object is not active, replica = 0
waitForReplicaCount(0, commandToCheckReplicas)
t.is('0', sh.exec(commandToCheckReplicas).stdout, 'Replica count should be 0.')

// produce one more msg to the different topic should trigger scale
sh.exec(`kubectl exec --namespace ${defaultNamespace} ${defaultKafkaClient} -- sh -exc 'echo "{\"text\": \"foo\"}" | kafka-console-producer --broker-list ${defaultCluster}-kafka-bootstrap.${defaultNamespace}:9092 --topic ${defaultTopic2}'`)
sh.exec(`sleep 20s`)
// produce a single msg to the default topic
// should turn scale object active, replica = 1
sh.exec(`kubectl exec --namespace ${defaultNamespace} ${defaultKafkaClient} -- sh -exc 'echo "{\"text\": \"foo\"}" | kafka-console-producer --broker-list ${defaultCluster}-kafka-bootstrap.${defaultNamespace}:9092 --topic ${defaultTopic}'`)
sh.exec(`sleep 5s`)
waitForReplicaCount(1, commandToCheckReplicas)
t.is('1', sh.exec(commandToCheckReplicas).stdout, 'Replica count should be 1.')

// produce one more msg to the different topic within the same group
// will turn total consumer group lag to 2.
// with lagThreshold as 1 -> making hpa AverageValue to 1
// this should turn nb of replicas to 2
// as desiredReplicaCount = totalLag / avgThreshold
sh.exec(`kubectl exec --namespace ${defaultNamespace} ${defaultKafkaClient} -- sh -exc 'echo "{\"text\": \"foo\"}" | kafka-console-producer --broker-list ${defaultCluster}-kafka-bootstrap.${defaultNamespace}:9092 --topic ${defaultTopic2}'`)
sh.exec(`sleep 5s`)
waitForReplicaCount(2, commandToCheckReplicas)
t.is('2', sh.exec(commandToCheckReplicas).stdout, 'Replica count should be 2.')

// make it 3 cause why not?
sh.exec(`kubectl exec --namespace ${defaultNamespace} ${defaultKafkaClient} -- sh -exc 'echo "{\"text\": \"foo\"}" | kafka-console-producer --broker-list ${defaultCluster}-kafka-bootstrap.${defaultNamespace}:9092 --topic ${defaultTopic}'`)
sh.exec(`sleep 5s`)
waitForReplicaCount(3, commandToCheckReplicas)
t.is('3', sh.exec(commandToCheckReplicas).stdout, 'Replica count should be 3.')
})

test.serial('Cleanup after multiple topics test', t=> {
Expand Down Expand Up @@ -481,5 +494,5 @@ spec:
metadata:
bootstrapServers: ${defaultCluster}-kafka-bootstrap.${defaultNamespace}:9092
consumerGroup: multiTopic
lagThreshold: '2'
lagThreshold: '1'
offsetResetPolicy: 'latest'`