Skip to content

feat(kafka-logger): support sasl conf#7782

Closed
biubiue wants to merge 33 commits into
apache:masterfrom
biubiue:patch-2
Closed

feat(kafka-logger): support sasl conf#7782
biubiue wants to merge 33 commits into
apache:masterfrom
biubiue:patch-2

Conversation

@biubiue

@biubiue biubiue commented Aug 24, 2022

Copy link
Copy Markdown
Contributor

Description

Fixes # (issue)

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

Comment thread apisix/plugins/kafka-logger.lua
Comment thread t/plugin/kafka-logger.t Outdated
@biubiue
biubiue requested a review from spacewander September 6, 2022 09:54
Comment thread t/plugin/kafka-logger.t Outdated
--- config
location /t {
content_by_lua_block {
local producer = require "resty.kafka.producer"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should test the kafka-logger plugin directly like other tests, instead of using the producer outside of the plugin.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Comment thread t/plugin/kafka-logger.t Outdated
Comment on lines +644 to +649
=== TEST 21: access
--- request
GET /hello
--- response_body
hello world
--- wait: 2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we can inject the producer.new like:

=== TEST 7: verify request
--- extra_init_by_lua
local cls = require("apisix.plugins.tencent-cloud-cls.cls-sdk")
cls.send_to_cls = function(self, logs)
if (#logs ~= 1) then
ngx.log(ngx.ERR, "unexpected logs length: ", #logs)
return
end
return true
end
--- request
GET /opentracing
--- response_body
opentracing
--- error_log
Batch Processor[tencent-cloud-cls] successfully processed the entries
--- wait: 0.5

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we can inject the producer.new like:

=== TEST 7: verify request
--- extra_init_by_lua
local cls = require("apisix.plugins.tencent-cloud-cls.cls-sdk")
cls.send_to_cls = function(self, logs)
if (#logs ~= 1) then
ngx.log(ngx.ERR, "unexpected logs length: ", #logs)
return
end
return true
end
--- request
GET /opentracing
--- response_body
opentracing
--- error_log
Batch Processor[tencent-cloud-cls] successfully processed the entries
--- wait: 0.5

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

Comment thread apisix/plugins/kafka-logger.lua Outdated
properties = {
mechanism = { type = "string", description = "mechanism" },
password = { type = "string", description = "password" },
user = { type = "string", description = "user" },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These fields should be required if the sasl config exists?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These fields should be required if the sasl config exists?

I modify these fields ,and mark required fields

Comment thread docs/en/latest/plugins/kafka-logger.md Outdated
| ---------------------- | ------- | -------- | -------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| broker_list | object | True | | | List of Kafka brokers (nodes). |
| sasl_config | object | False | | | Kafka sasl conf. |
| sasl_config.mechanism | string | False | | | Kafka mechanism. |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add the default value here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Add the default value here.

ok

type = "object",
description = "sasl config",
properties = {
mechanism = { type = "string", description = "mechanism", default = "PLAIN" },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The mechanism should be restricted to only use a few enumerations like PLAIN, SCRAM and so on.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The mechanism should be restricted to only use a few enumerations like PLAIN, SCRAM and so on.

ok, I change it

@biubiue biubiue Sep 8, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The mechanism should be restricted to only use a few enumerations like PLAIN, SCRAM and 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OK, SCRAM-SHA-256 is copied from Confluent docs. No worries at all.

@spacewander

Copy link
Copy Markdown
Member

Please make the CI pass, thanks!

@biubiue

biubiue commented Sep 9, 2022

Copy link
Copy Markdown
Contributor Author

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.

Comment thread t/plugin/kafka-logger.t Outdated
            ngx.log(ngx.ERR, "unexpected broker_list length: ", #broker_list)
            return nil
        end
        return producer

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The producer should not be returned here, you can see that the original returned is a table.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The producer should 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 .

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.

4 participants