Fix OpenAI connection-pool-metrics-enabled being ignored - #6802
Open
wantaekchoi wants to merge 1 commit into
Open
Fix OpenAI connection-pool-metrics-enabled being ignored#6802wantaekchoi wants to merge 1 commit into
connection-pool-metrics-enabled being ignored#6802wantaekchoi wants to merge 1 commit into
Conversation
`OpenAiAutoConfigurationUtil.resolveCommonProperties` builds the `ResolvedConnectionProperties` that all six OpenAI model auto-configurations read, but it never copies `connectionPoolMetricsEnabled` from either the model-level or the common-level properties. The resolved value stays at its `false` default, the auto-configurations hand a null `MeterRegistry` to the OpenAI clients, and `OkHttpConnectionPoolMetrics` is never bound, so the documented opt-in has no effect. Propagate the flag next to the sibling booleans, using the same model-or-common resolution they use. Signed-off-by: wantaek <wantaekchoi@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
OpenAiAutoConfigurationUtil.resolveCommonPropertiesbuilds theResolvedConnectionPropertiesinstance that every OpenAI model auto-configuration reads. It resolves each connection property from the model-level or the common-level properties, but there is no branch forconnectionPoolMetricsEnabled, so the resolved value stays at itsfalsedefault whatever the user configures.All six OpenAI auto-configurations (chat, embedding, image, moderation, audio speech, audio transcription) pick their meter registry from that resolved value:
The parameter is named
commonProperties, but each caller passesresolvedPropertiesinto it. So all six passnullto the OpenAI clients, andSpringAiOpenAiHttpClientbindsOkHttpConnectionPoolMetricsonly when the registry is non-null.The opt-in that
openai-chat.adoctells users to set therefore does nothing:spring.ai.openai.chat.connection-pool-metrics-enabled=trueNeither does
spring.ai.openai.connection-pool-metrics-enabled, the row listed in the property table of all six OpenAI reference pages. Auto-configuration never registers anokhttp.pool.*gauge.Commit 386df9c added the property and the six consumers but did not touch
OpenAiAutoConfigurationUtil.Changes
Resolve
connectionPoolMetricsEnablednext to the sibling booleans, with the resolution they already use:For a primitive boolean defaulting to
false, that OR is the same rule the other properties follow: take the model value unless it is the default, otherwise take the common value. Both documented keys start working, and the property stays opt-in.It does not let a model-level
falseoverride a common-leveltrue. Distinguishing "explicitly false" from "not set" needs a nullableBoolean, andisMicrosoftFoundryandisGitHubModelsdo not do that either.I checked the rest of the resolver rather than this field alone. Comparing every setter on
AbstractOpenAiPropertiesagainst the onesresolveCommonPropertiesassigns,connectionPoolMetricsEnabledwas the only property left unresolved.Testing
OpenAiChatPropertiesTests.connectionPoolMetricsEnabledstarts the chat auto-configuration withspring.ai.openai.connection-pool-metrics-enabled=trueand aSimpleMeterRegistry, then asserts thatokhttp.pool.connection.countgauges are registered. Without the change it fails withExpecting actual not to be empty, since no gauge is bound.connectionPoolMetricsDisabledByDefaultpins the opt-in default.OpenAiAutoConfigurationUtilTestsadds three resolver cases: enabled at the common level only, enabled at the model level only, and enabled at neither. The first two fail without the change.passes with 29 tests.
starters/spring-ai-starter-model-openaiandauto-configurations/models/spring-ai-autoconfigure-model-mistral-ai, the modules that depend on it, pass with 12 tests../mvnw -Dmaven.build.cache.enabled=false clean package -DskipITsalso passes, with 5662 tests and no failures.