Claus Ibsen created CAMEL-27618:
-----------------------------------

             Summary: camel-azure-cosmosdb: unchecked item partition key, no-op 
option, headers missing in metadata
                 Key: CAMEL-27618
                 URL: https://issues.apache.org/jira/browse/CAMEL-27618
             Project: Camel
          Issue Type: Bug
          Components: camel-cosmosdb
            Reporter: Claus Ibsen
             Fix For: 4.24.0


Found while improving the option descriptions of camel-azure-cosmosdb for 
CAMEL-23832 (PR https://github.com/apache/camel/pull/30956).
These are separate problems of the component; the descriptions PR only 
documents the current behavior.

h4. 1. A missing item partition key is not detected, and the partition key is 
always a String
{{CosmosDbConfigurationOptionsProxy.getItemPartitionKey()}} always returns 
{{new PartitionKey(value)}}, where the value is the 
{{CamelAzureCosmosDbItemPartitionKey}} header or the {{itemPartitionKey}} 
option, both read as a String.
When neither is set, this is {{new PartitionKey(null)}}, the JSON null 
partition key value. {{CosmosDbUtils.validateIfParameterIsNotEmpty()}} in 
{{CosmosDbContainerOperations}} never fails for a {{PartitionKey}} object, so 
createItem, upsertItem, replaceItem, deleteItem, readItem and readAllItems run 
with a null partition key. The user sees an error or a not-found response from 
Cosmos DB, or an empty result for readAllItems, instead of a clear message that 
the partition key is missing.
As the value is always a String, an item whose partition key value is a number 
or a boolean cannot be addressed: a header value of 5 becomes the partition key 
"5".
Proposed change: fail with a clear message when no partition key is set (the 
null partition key could stay possible on purpose, for example with a header of 
type {{PartitionKey}}), and keep a {{PartitionKey}}, number or boolean header 
value as it is.

h4. 2. clientTelemetryEnabled has no effect
{{CosmosDbClientFactory.createBasicClient()}} passes the option to 
{{CosmosClientBuilder.clientTelemetryEnabled(boolean)}}. In azure-cosmos 4.75.0 
that method is deprecated and does nothing: it only returns the builder.
Proposed change: deprecate the option (and remove it in a later release), or 
map it to {{CosmosClientBuilder.clientTelemetryConfig()}} if that matches its 
intent.

h4. 3. The headers are not in the component metadata
The constants in {{CosmosDbConstants}} have no {{@Metadata}}, and 
{{@UriEndpoint}} of {{CosmosDbEndpoint}} has no {{headersClass}}. So the 
catalog, the Endpoint DSL ({{EndpointHeaderBuilders}}) and the generated header 
table of the doc page list no headers. They are only in hand-written tables of 
{{azure-cosmosdb-component.adoc}}.
Proposed change: add {{@Metadata}} (description, javaType, label) to the 
constants, set {{headersClass = CosmosDbConstants.class}}, and remove the 
hand-written tables.

h4. 4. The header name of RESOURCE_ID is misspelled
{{CosmosDbConstants.RESOURCE_ID}} is {{CamelAzureCosmosDbRecourseId}} 
("Recourse" instead of "Resource"). The producer sets it for the database and 
container operations.
Proposed change: rename it to {{CamelAzureCosmosDbResourceId}}, following the 
upgrade policy for header names in {{design/headers.adoc}} (an upgrade guide 
entry, possibly setting both names for one release).

h4. 5. databaseEndpoint is marked required, but is only required without 
cosmosAsyncClient
{{databaseEndpoint}} has {{@Metadata(required = true)}} in 
{{CosmosDbConfiguration}}, but {{CosmosDbComponent.validateConfigurations()}} 
only requires it when {{cosmosAsyncClient}} is not set. Tooling that checks 
required options reports an endpoint that only uses {{cosmosAsyncClient}} as 
invalid.
Proposed change: drop {{required = true}}, as the component validation already 
covers the case.

h4. 6. The default of consistencyLevel is not one of its enum values
The metadata of {{consistencyLevel}} has the default value {{SESSION}}, while 
its enum values are {{Strong}}, {{BoundedStaleness}}, {{Session}}, {{Eventual}} 
and {{ConsistentPrefix}} (the {{toString()}} of 
{{com.azure.cosmos.ConsistencyLevel}}). Both spellings convert, but a tool that 
compares the default with the enum values finds no match.
Proposed change: use the same spelling for the default and the enum values, for 
example {{enums}} on the {{@UriParam}} with the constant names.

h4. 7. indexingPolicy has the label common
{{indexingPolicy}} has the label {{common, advanced}}, but the consumer does 
not use it: {{CosmosDbConsumer.getContainerOperations()}} never calls 
{{withIndexingPolicy()}}. Only the producer uses it, for a container that it 
creates.
Proposed change: change the label to {{producer, advanced}}.

h4. 8. The doc page asks for an Azure Storage account
The "Prerequisites" of {{azure-cosmosdb-component.adoc}} say "You must have a 
valid Windows Azure Storage account". The component needs an Azure Cosmos DB 
account.
Proposed change: fix the sentence.

_Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to