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: added a new text embedded format #858

Merged
merged 17 commits into from
Mar 4, 2024

Conversation

antonio-pedro99
Copy link
Member

This fixes #739

Note: I closed #836 and started a fresh PR.

@antonio-pedro99
Copy link
Member Author

antonio-pedro99 commented Dec 28, 2023

@ppatierno all tests are now passing.
I wonder why the Docs build is failing, as I did not change anything related to docs!

@ppatierno
Copy link
Member

@antonio-pedro99 build is failing on doc with following error ...

ERROR: Uncommitted changes in documentation:
M	documentation/book/api/paths.adoc
Run the following to add up-to-date resources:
  make docu_api \
    && git add documentation/book/ \
    && git commit -s -m 'Update generated documentation'

@antonio-pedro99
Copy link
Member Author

antonio-pedro99 commented Dec 29, 2023

@antonio-pedro99 build is failing on doc with following error ...

ERROR: Uncommitted changes in documentation:
M	documentation/book/api/paths.adoc
Run the following to add up-to-date resources:
  make docu_api \
    && git add documentation/book/ \
    && git commit -s -m 'Update generated documentation'

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.118 s
[INFO] Finished at: 2023-12-29T20:49:05+05:30
[INFO] ------------------------------------------------------------------------
[WARNING] 
[WARNING] Plugin validation issues were detected in 1 plugin(s)
[WARNING] 
[WARNING]  * io.github.swagger2markup:swagger2markup-maven-plugin:1.3.7
[WARNING] 
[WARNING] For more or less details, use 'maven.plugin.validation' property with one of the values (case insensitive): [BRIEF, DEFAULT, VERBOSE]
[WARNING] 
[ERROR] Failed to execute goal io.github.swagger2markup:swagger2markup-maven-plugin:1.3.7:convertSwagger2markup (generate-apidoc) on project kafka-bridge: Failed to execute goal 'convertSwagger2markup': Error creating extended parser class: Could not determine whether class 'org.pegdown.Parser$$parboiled' has already been loaded: Unable to make protected final java.lang.Class java.lang.ClassLoader.findLoadedClass(java.lang.String) accessible: module java.base does not "opens java.lang" to unnamed module @358ab600 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
make: *** [Makefile:63: docu_api] Error 1

@ppatierno
Copy link
Member

Just ran on your branch locally the command from Azure pipeline ...

mvn -e -V -B -P apidoc io.github.swagger2markup:swagger2markup-maven-plugin:convertSwagger2markup@generate-apidoc

and it works like a charm. It produces a documentation/book/api/paths.adoc file which you should push.

@antonio-pedro99
Copy link
Member Author

Just ran on your branch locally the command from Azure pipeline ...

mvn -e -V -B -P apidoc io.github.swagger2markup:swagger2markup-maven-plugin:convertSwagger2markup@generate-apidoc

and it works like a charm. It produces a documentation/book/api/paths.adoc file which you should push.

I need to double-check, it still does not work on my side

@ppatierno
Copy link
Member

@antonio-pedro99 I have just pushed on your branch with the missing file. Please update your local branch checking out the changes.

@ppatierno ppatierno added this to the 0.28.0 milestone Dec 31, 2023
@antonio-pedro99
Copy link
Member Author

@antonio-pedro99 I have just pushed on your branch with the missing file. Please update your local branch checking out the changes.

work done!
Waiting for more reviews

Copy link
Member

@scholzj scholzj left a comment

Choose a reason for hiding this comment

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

@antonio-pedro99 Thanks for the PR. I wonder how the conversion / error handling works here. I guess it either does not work that well, or it should be documented how does it (not) work.

For example, when I sent a following produce request, where the format is text but the value is JSON, it seems to pass fine:

curl -v -X POST \
    192.168.1.220:8080/topics/kafka-test-apps \
    -H 'content-type: application/vnd.kafka.text.v2+json' \
    -d '{
      "records": [
          {
              "key": "tricky-payload",
              "value": {"Ahoj": "Svete"}
          }
      ]
  }'

But when I try to consume it, I get empty value:

curl -X GET http://192.168.1.220:8080/consumers/my-bridge-group/instances/my-http-client/records \
  -H 'accept: application/vnd.kafka.text.v2+json'
[
  {
    "topic": "kafka-test-apps",
    "key": "tricky-payload",
    "value": "",
    "partition": 0,
    "offset": 69
  }
]

This seems to be the issue with the producer here where the bridge decodes the JSON as empty string. When I produce it as JSON and consume as text, I get the more expected "value": "{\"Ahoj\":\"Svete\"}". Not sure this is a bug or expected. But if ti is expected, I thik it is worth documenting how to produce the messages.

The response seems to have also a wrong content type application/vnd.kafka.json.v2+json. That looks like something you have to fix in HttpSink BridgeEndpoint.pollHandler.

@antonio-pedro99
Copy link
Member Author

@antonio-pedro99 Thanks for the PR. I wonder how the conversion / error handling works here. I guess it either does not work that well, or it should be documented how does it (not) work.

For example, when I sent a following produce request, where the format is text but the value is JSON, it seems to pass fine:

curl -v -X POST \
    192.168.1.220:8080/topics/kafka-test-apps \
    -H 'content-type: application/vnd.kafka.text.v2+json' \
    -d '{
      "records": [
          {
              "key": "tricky-payload",
              "value": {"Ahoj": "Svete"}
          }
      ]
  }'

But when I try to consume it, I get empty value:

curl -X GET http://192.168.1.220:8080/consumers/my-bridge-group/instances/my-http-client/records \
  -H 'accept: application/vnd.kafka.text.v2+json'
[
  {
    "topic": "kafka-test-apps",
    "key": "tricky-payload",
    "value": "",
    "partition": 0,
    "offset": 69
  }
]

This seems to be the issue with the producer here where the bridge decodes the JSON as empty string. When I produce it as JSON and consume as text, I get the more expected "value": "{\"Ahoj\":\"Svete\"}". Not sure this is a bug or expected. But if ti is expected, I thik it is worth documenting how to produce the messages.

That is a good catch, tbh I am not sure how it is supposed to be handled, I implemented the converter following our discussions on #739. I think it's worth to think about how to handle this case. Allow me some time to think a bit more.

The response seems to have also a wrong content type application/vnd.kafka.json.v2+json. That looks like something you have to fix in HttpSink BridgeEndpoint.pollHandler.

This is fixed in the recent commit.

@ppatierno
Copy link
Member

I think what Jakub found is a bug and the way it should work is that you could produce using an embedded format but receiving with a different one by accepting that there could be some "differences" in what you get.
I mean, you could produce using JSON format and value being a JSON but then you should be able to consume using TEXT format and getting the value as a text not a json (in the end the json value is a .... text). Of course, taking into account the escape of quoting fields in the JSON value.

@scholzj
Copy link
Member

scholzj commented Jan 2, 2024

I mean, you could produce using JSON format and value being a JSON but then you should be able to consume using TEXT format and getting the value as a text not a json (in the end the json value is a .... text). Of course, taking into account the escape of quoting fields in the JSON value.

I think that works fine in the consumer IIRC what I was trying. It is more what happens the producer with text format sends a JSON where we can maybe throw an error or something.

@ppatierno
Copy link
Member

It is more what happens the producer with text format sends a JSON where we can maybe throw an error or something.

Regarding this, because the producer is sending with "text" format and it's a JSON, why and how the bridge should know to validate it's a valid JSON. I mean, it's a plain text. Of course, it can contain a JSON but does it really matter for the bridge? It's just bringing text.

@scholzj
Copy link
Member

scholzj commented Jan 2, 2024 via email

@antonio-pedro99
Copy link
Member Author

Hey @ppatierno @scholzj, just got busy with some work here. I will get back to you guys over the weekend.

@ppatierno
Copy link
Member

@antonio-pedro99 are you willing to address this soon?

@antonio-pedro99
Copy link
Member Author

@antonio-pedro99 are you willing to address this soon?

Yes , I will!

@antonio-pedro99
Copy link
Member Author

Are you planning any release soon?

@ppatierno
Copy link
Member

Are you planning any release soon?

No specific plan for now, I was just wondering if you were still interested in it because of 2 weeks after your last comment :-)

@antonio-pedro99
Copy link
Member Author

Are you planning any release soon?

No specific plan for now, I was just wondering if you were still interested in it because of 2 weeks after your last comment :-)

Yeah, I try to complete this on this weekend.

@ppatierno
Copy link
Member

@antonio-pedro99 any news?

@antonio-pedro99
Copy link
Member Author

antonio-pedro99 commented Jan 31, 2024 via email

@antonio-pedro99
Copy link
Member Author

I mean, you could produce using JSON format and value being a JSON but then you should be able to consume using TEXT format and getting the value as a text not a json (in the end the json value is a .... text). Of course, taking into account the escape of quoting fields in the JSON value.

I think that works fine in the consumer IIRC what I was trying. It is more what happens the producer with text format sends a JSON where we can maybe throw an error or something.

what is consumer IIRC?

@antonio-pedro99
Copy link
Member Author

It is more what happens the producer with text format sends a JSON where we can maybe throw an error or something.

Regarding this, because the producer is sending with "text" format and it's a JSON, why and how the bridge should know to validate it's a valid JSON. I mean, it's a plain text. Of course, it can contain a JSON but does it really matter for the bridge? It's just bringing text.

So you suggest validating the JSON and make the possible conversion?

If the format is text, it makes more sense to expect text only.

@scholzj
Copy link
Member

scholzj commented Feb 28, 2024

Looks like the build failed on checkstyle:

[ERROR] /home/vsts/work/1/s/src/main/java/io/strimzi/kafka/bridge/http/converter/HttpTextMessageConverter.java:27:5: NPath Complexity is 217 (max allowed is 200). [NPathComplexity]

Maybe you can have a look if the code can be fixed - if not, you should be able to use @SuppressWarnings("checkstyle:NPathComplexity") annotation to override the warning. The code does not seem to be somehow super bad in that file.

antonio-pedro99 and others added 15 commits March 4, 2024 12:57
Signed-off-by: Antonio Pedro <[email protected]>
Signed-off-by: Paolo Patierno <[email protected]>
Signed-off-by: Antonio Pedro <[email protected]>
Signed-off-by: Antonio Pedro <[email protected]>
Signed-off-by: Antonio Pedro <[email protected]>
Signed-off-by: Antonio Pedro <[email protected]>
Signed-off-by: Antonio Pedro <[email protected]>
Signed-off-by: Antonio Pedro <[email protected]>
Signed-off-by: Antonio Pedro <[email protected]>
This reverts commit b009700.

Signed-off-by: Antonio Pedro <[email protected]>
@antonio-pedro99
Copy link
Member Author

@antonio-pedro99 I think you had problem with rebase. There are changes which are already in main, see all the "endpoint" classes.

Sorry, might be fixed now!

Copy link
Member

@ppatierno ppatierno left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the PR!
@scholzj do you have anything to add?

Copy link
Member

@scholzj scholzj left a comment

Choose a reason for hiding this comment

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

LGTM. But I guess we should have CHANGELOG record for this as well?

@ppatierno
Copy link
Member

LGTM. But I guess we should have CHANGELOG record for this as well?

Right. @antonio-pedro99 can you add a line in the CHANGELOG about this new feature?

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
Signed-off-by: António Pedro <[email protected]>
@ppatierno
Copy link
Member

@scholzj any further comments or can I merge this?

@scholzj scholzj merged commit c3e96c7 into strimzi:main Mar 4, 2024
13 checks passed
@antonio-pedro99 antonio-pedro99 deleted the add-text-format branch March 4, 2024 17:24
@antonio-pedro99 antonio-pedro99 self-assigned this Mar 12, 2024
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.

Add a new string embedded format
3 participants