oscerd opened a new pull request, #29072: URL: https://github.com/apache/camel/pull/29072
Fixes [CAMEL-26230](https://issues.apache.org/jira/browse/CAMEL-26230), found while adding the catalog body types (CAMEL-24961). ## 1. A Point with no fields is dropped without an error **Was:** the producer passed the Point to the client, which skips a Point without a field to write, so the exchange completed and nothing was written. **Now:** a Point whose line protocol is empty, that is a Point with no field or only fields whose value is null, NaN or infinite (the client leaves those out), fails the exchange with a `CamelInfluxDb2Exception` and nothing is sent. This applies to a Point body, to a Point converted from a Map body, and to each Point of a Points body (the message names its index; no point of the batch is written). The check uses the line protocol of the client itself, so it matches exactly what the client would skip. ## 2. The endpoint calls the server at startup even with autoCreateOrg=false **Was:** the endpoint always looked the organization up when it started, then the bucket, which looked the organization up a second time, whatever `autoCreateOrg` and `autoCreateBucket` were, so a route could not start while InfluxDB was down. **Now:** the organization is looked up (and created when missing) only when `autoCreateOrg` is true, and the bucket only when `autoCreateBucket` is true, each once. The write path needs neither lookup: a write sends the organization and the bucket by name (the organization ID is only needed to create a bucket). So with both options false the endpoint does not call InfluxDB at startup and the route starts while InfluxDB is down; a missing organization or bucket then fails the write. With `autoCreateOrg=false` and `autoCreateBucket=true`, the organization is looked up only when the bucket must be created, and when it does not exist the endpoint fails to start with a message that names the bucket and the organization (it used to fail inside the client with "Expecting a non-empty string for Organization Id"). ## 3. The Map converter mutates the caller's Map **Was:** the converter removed `CamelInfluxDB2MeasurementName` from the body Map and put it back, so an immutable Map (`Map.of`) failed with `UnsupportedOperationException`, and a Map shared with other code was changed while the point was built. **Now:** the fields are a copy of the Map without the measurement key; the Map of the caller is not touched. ## Tests `InfluxDb2ProducerWriteFailureTest` writes with the real client to a local HTTP server that plays the write API of InfluxDB 2.x: - A Point with no field, with only a null field, with only a NaN field and with only an infinite field each fail the exchange with the `CamelInfluxDb2Exception` and its message, and no write request reaches the server. - A Map body with only the measurement name fails the same way. - A Points body whose second point has no field fails with a message that names index 1, and none of its points is written. - A Points body with a null element still writes the other point (unchanged). - An immutable `Map.of` body is written. `InfluxDb2EndpointStartupTest` uses a local HTTP server that plays the organizations, buckets and write APIs and records the requests: - With `autoCreateOrg=false&autoCreateBucket=false` no request is sent at startup, and the write names the organization and the bucket. - With the same options the route starts when nothing listens on the port of the client, and the write then fails the exchange. - The defaults look the organization and the bucket up once each, and create both when they are missing (the bucket with the ID of the new organization). - With `autoCreateOrg=false` only the bucket is looked up; a missing bucket is created in the organization, found by name; when that organization does not exist the route fails to start with the message that names them. `CamelInfluxDbConverterTest` converts a `Map.of` body, and checks that a `LinkedHashMap` keeps its entries and their order. `InfluxDb2ProducerTest.writePoint` and `writePoints` wrote a Point without fields and expected success; their points now have a field. Revert check: with the change to `src/main/java` reverted, 16 of the 17 new tests fail: the startup tests on the duplicate and unneeded lookups, on the route that does not start while the server is down, and on the client's own error for a missing organization; the point tests because the exchange completes with nothing written; the Map tests with `UnsupportedOperationException` and the reordered keys. The one that passes is the null element of Points, which checks behaviour that does not change. Module: 38 tests, 0 failures (21 before). ## Docs and generated files - `influxdb2-component.adoc`: a paragraph on the points without fields, a section on the organization and the bucket at startup, and a sentence saying the Map body is not changed. The catalog copy of the doc is updated. - `@BodyTypes` description of the producer input mentions that a Point without a field that has a value fails; the component JSON and its catalog copy are regenerated. No option or header changed. - Upgrade guide entry for 4.24: the new failure for a Point without fields, and the startup lookups. ## Not changed - Startup lookups stay at endpoint start, gated by the two options, instead of being moved to the first write: a lazy lookup would add state to the producer, and the organization and bucket of a write can come from the `CamelInfluxDB2Org` / `CamelInfluxDB2Bucket` headers, which auto-creation never covered. - With the defaults (`autoCreateOrg=true`, `autoCreateBucket=true`) the endpoint still needs InfluxDB to start, as it must check and create them. A `ping` endpoint also still runs these lookups when the options are true. - Records: a record line without a field is sent and InfluxDB rejects it, which already fails the exchange; the client only leaves out an empty record string, which has nothing to write, so Record and Records bodies are not checked. - A null element of a Points body has nothing to write and is still left out by the client, and an empty Points body is still a write of nothing. - Measurement and Measurements bodies are converted to points inside the client (by its internal mapper), so a measurement whose columns are all null is not checked. Main only, as the other fixes of the CAMEL-24961 follow-ups. _Claude Code on behalf of Andrea Cosentino (oscerd)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
