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

feat: add brokers field to support set broker with the same host in kafka-logger plugin #7999

Merged
merged 9 commits into from
Oct 8, 2022

Conversation

starsz
Copy link
Contributor

@starsz starsz commented Sep 27, 2022

Description

Fix #7998

Because the key in the JSON object should be different.
And the original design we use map to store the broker list, so we can't create a broker with the same host.

Now, I add a new filed brokers (It's an array type), then we can create brokers with the same host.

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)

@starsz starsz changed the title feat: support set broker array in kafka-logger plugin feat: add brokers field to support set broker with the same host in kafka-logger plugin Sep 29, 2022
@starsz starsz marked this pull request as ready for review September 29, 2022 07:55
@@ -251,3 +284,4 @@ end


return _M

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the empty line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

apisix/plugins/kafka-logger.lua Show resolved Hide resolved
| broker_list | object | True | | | List of Kafka brokers (nodes). |
| broker_list | deprecated | True | | | Use `brokers` instead. List of Kafka brokers. (nodes). |
| brokers | array | True | | | List of Kafka brokers (nodes). |
| brokers.host | string | True | | | The host of Kafka broker |
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
| brokers.host | string | True | | | The host of Kafka broker |
| brokers.host | string | True | | | The host of Kafka broker, e.g., `192.168.1.1`. |

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

t/plugin/kafka-logger2.t Show resolved Hide resolved
tokers
tokers previously approved these changes Sep 30, 2022
tzssangglass
tzssangglass previously approved these changes Sep 30, 2022
@@ -37,7 +37,10 @@ It might take some time to receive the log data. It will be automatically sent a

| Name | Type | Required | Default | Valid values | Description |
| ---------------------- | ------- | -------- | -------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| broker_list | object | True | | | List of Kafka brokers (nodes). |
| broker_list | deprecated | True | | | Use `brokers` instead. List of Kafka brokers. (nodes). |
Copy link
Member

Choose a reason for hiding this comment

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

It would be better to put the "deprecated" in the Description instead of the Type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

| broker_list | object | True | | | List of Kafka brokers (nodes). |
| broker_list | deprecated | True | | | Use `brokers` instead. List of Kafka brokers. (nodes). |
| brokers | array | True | | | List of Kafka brokers (nodes). |
| brokers.host | string | True | | | The host of Kafka broker, e.g, `192.168.1.1`. |
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to update the Chinese version?
CC @SylviaBABY

Copy link
Member

Choose a reason for hiding this comment

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

Do we need to update the Chinese version? CC @SylviaBABY

I think we need to update the CN version. But you can merge this first. I'll update the CN version depending on this part later

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me update the Chinese version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -199,15 +225,24 @@ function _M.log(conf, ctx)
end

-- reuse producer via lrucache to avoid unbalanced partitions of messages in kafka
local broker_list = core.table.new(core.table.nkeys(conf.broker_list), 0)
local length = conf.broker_list and core.table.nkeys(conf.broker_list) or #conf.brokers
Copy link
Member

Choose a reason for hiding this comment

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

Just FYI: if we don't need to rewrite the content of table, we can use core.table.clone instead of alloc + insert in loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me update it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the remind. Improved.

@starsz starsz dismissed stale reviews from tzssangglass and tokers via 2d8f189 September 30, 2022 07:20
@spacewander spacewander merged commit e9ec16f into apache:master Oct 8, 2022
@starsz starsz deleted the feat_support_broker_array branch October 9, 2022 01:19
Liu-Junlin pushed a commit to Liu-Junlin/apisix that referenced this pull request Nov 4, 2022
…afka-logger plugin (apache#7999)

Co-authored-by: Sylvia <39793568+SylviaBABY@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants