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: custom headers can be specified per request (query/write) #108

Merged
merged 7 commits into from
Mar 7, 2024

Conversation

bednar
Copy link
Member

@bednar bednar commented Mar 6, 2024

Closes #109


https://influxdata.slack.com/archives/C5BSZ026L/p1709551752382859


Proposed Changes

This add support for use the custom headers per request:

ClientConfig config = new ClientConfig.Builder()
     .host("https://us-east-1-1.aws.cloud2.influxdata.com")
     .token("my-token".toCharArray())
     .database("my-database")
     .build();
 
 try (InfluxDBClient client = InfluxDBClient.getInstance(config)) {
     //
     // Write with custom headers
     //
     WriteOptions writeOptions = new WriteOptions(
         Map.of("X-Tracing-Id", "852")
     );
     client.writeRecord("mem,tag=one value=1.0", writeOptions);
     
     //
     // Query with custom headers
     //
     QueryOptions queryOptions = new QueryOptions(
         Map.of("X-Tracing-Id", "852")
     );
     Stream<Object[]> rows = client.query("select * from cpu", queryOptions);

 } catch (Exception e) {
     throw new RuntimeException(e);
 } 

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • Tests pass
  • Commit messages are conventional
  • Sign CLA (if not already signed)

Copy link

codecov bot commented Mar 6, 2024

Codecov Report

Attention: Patch coverage is 95.00000% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 88.53%. Comparing base (da932f7) to head (0eb5ebc).

Files Patch % Lines
...ava/com/influxdb/v3/client/write/WriteOptions.java 85.71% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #108      +/-   ##
==========================================
+ Coverage   88.39%   88.53%   +0.14%     
==========================================
  Files          15       15              
  Lines         836      855      +19     
  Branches      120      129       +9     
==========================================
+ Hits          739      757      +18     
  Misses         42       42              
- Partials       55       56       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bednar bednar requested a review from karel-rehor March 6, 2024 14:00
Copy link
Contributor

@karel-rehor karel-rehor left a comment

Choose a reason for hiding this comment

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

Found a couple of nit-picks.

  • Comment in ClientConfig.java is worded if... than not if... then
  • Minor lint issue in RestClient.java with two arguments on the same line
  • The internal Builder class of WriteOptions does not support the new property headers

@@ -122,8 +122,7 @@ public void checkServerTrusted(
void request(@Nonnull final String path,
@Nonnull final HttpMethod method,
@Nullable final byte[] data,
@Nullable final Map<String, String> headers,
@Nullable final Map<String, String> queryParams) {
@Nullable final Map<String, String> queryParams, @Nullable final Map<String, String> headers) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Two arguments here should probably follow style of one arg per line for readability.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@@ -140,6 +140,7 @@ public String getDatabase() {

/**
* Gets the default precision to use for the timestamp of points.
* If no precision is specified than 'ns' is used.
Copy link
Contributor

Choose a reason for hiding this comment

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

"than" should be "then"

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@@ -63,42 +70,78 @@ public final class WriteOptions {
private final WritePrecision precision;
private final Integer gzipThreshold;
private final Map<String, String> defaultTags;
private final Map<String, String> headers;
Copy link
Contributor

Choose a reason for hiding this comment

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

The Builder class (ln 230) does not support this property.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@bednar bednar requested a review from karel-rehor March 7, 2024 12:23
Copy link
Contributor

@karel-rehor karel-rehor left a comment

Choose a reason for hiding this comment

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

Tests pass locally. Looks good to go.

@bednar
Copy link
Member Author

bednar commented Mar 7, 2024

@karel-rehor thx

@bednar bednar merged commit aa5509b into main Mar 7, 2024
10 checks passed
@bednar bednar deleted the headers-per-request branch March 7, 2024 12:37
@bednar bednar added this to the 0.7.0 milestone Mar 7, 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.

A typo in WriteOptions.gzipThresholdSafe
2 participants