feat(kafka-logger): support sasl conf#7782
Conversation
| --- config | ||
| location /t { | ||
| content_by_lua_block { | ||
| local producer = require "resty.kafka.producer" |
There was a problem hiding this comment.
We should test the kafka-logger plugin directly like other tests, instead of using the producer outside of the plugin.
There was a problem hiding this comment.
We should test the kafka-logger plugin directly like other tests, instead of using the producer outside of the plugin.
Em... I maybe not understand https://github.com/apache/apisix/pull/7782#discussion_r956718372 .
OK, I will add test case like others
| === TEST 21: access | ||
| --- request | ||
| GET /hello | ||
| --- response_body | ||
| hello world | ||
| --- wait: 2 |
There was a problem hiding this comment.
we can inject the producer.new like:
apisix/t/plugin/tencent-cloud-cls.t
Lines 220 to 236 in 2aa5c48
There was a problem hiding this comment.
we can inject the producer.new like:
apisix/t/plugin/tencent-cloud-cls.t
Lines 220 to 236 in 2aa5c48
Em, like this?
=== TEST 20: create producer with sasl_config
--- extra_init_by_lua
local producer = require("resty.kafka.producer")
local klogger = require("apisix.plugins.kafka-logger")
producer.new = function(klogger)
if (!klogger.sasl_config) then
ngx.say("create producer without sasl_config")
return producer
end
producer.sasl_config = klogger.sasl_config
ngx.say("create producer with sasl_config")
return producer
end
--- request
GET /hello
--- response_body
hello world
--- wait: 2
| properties = { | ||
| mechanism = { type = "string", description = "mechanism" }, | ||
| password = { type = "string", description = "password" }, | ||
| user = { type = "string", description = "user" }, |
There was a problem hiding this comment.
These fields should be required if the sasl config exists?
There was a problem hiding this comment.
These fields should be required if the sasl config exists?
I modify these fields ,and mark required fields
| | ---------------------- | ------- | -------- | -------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ||
| | broker_list | object | True | | | List of Kafka brokers (nodes). | | ||
| | sasl_config | object | False | | | Kafka sasl conf. | | ||
| | sasl_config.mechanism | string | False | | | Kafka mechanism. | |
There was a problem hiding this comment.
Add the default value here.
ok
| type = "object", | ||
| description = "sasl config", | ||
| properties = { | ||
| mechanism = { type = "string", description = "mechanism", default = "PLAIN" }, |
There was a problem hiding this comment.
The mechanism should be restricted to only use a few enumerations like PLAIN, SCRAM and so on.
There was a problem hiding this comment.
The
mechanismshould be restricted to only use a few enumerations likePLAIN,SCRAMand so on.
ok, I change it
There was a problem hiding this comment.
The
mechanismshould be restricted to only use a few enumerations likePLAIN,SCRAMand so on.
Just now I review lua-resty-kafka ,
Write this local MECHANISM_SCRAMSHA256 = "SCRAM-SHA-256" -- to do, so SCRAM-SHA-256 maybe not work.
There was a problem hiding this comment.
OK, SCRAM-SHA-256 is copied from Confluent docs. No worries at all.
|
Please make the CI pass, thanks! |
Yeah,I also want to make CI pass, but write test case ,it’s not easy for me. I will do it soon. |
| ngx.log(ngx.ERR, "unexpected broker_list length: ", #broker_list) | ||
| return nil | ||
| end | ||
| return producer |
There was a problem hiding this comment.
The producer should not be returned here, you can see that the original returned is a table.
There was a problem hiding this comment.
The
producershould not be returned here, you can see that the original returned is a table.
Hi, when inject producer.new,it also dependency client.new. It means I will need inject client.new .
Description
Fixes # (issue)
Checklist