Skip to content

[Bundle] Track complexity - #5926

Open
Fernando Henrique Inocêncio Borba Ferreira (fhibf) wants to merge 15 commits into
mainfrom
user/fhibf/bundleComplexity
Open

Fernando Henrique Inocêncio Borba Ferreira (fhibf) wants to merge 15 commits into
mainfrom
user/fhibf/bundleComplexity

Conversation

@fhibf

@fhibf Fernando Henrique Inocêncio Borba Ferreira (fhibf) commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

Tracking the complexity of bundles with BundleHandlerComplexyCalculator. Different aspects of bundles are considered as part of the complexity calculation.

Additionally, this complexity is now included as part of the latency metric (as a dimension).

Other changes I've made:

  • Promoted a private class to internal: BundleHandlerInternalOperationExecutionContext
  • Removed BundleEndpointMetricEmitterAttribute, now the latency signal is emitted from BundleHandler.
  • Delete tests related to BundleEndpointMetricEmitterAttribute (as this component was removed).
  • Add tests around the bundle complexity calculation.

Related issues

Addresses AB#209754.

Testing

Describe how this change was tested.

FHIR Team Checklist

  • Update the title of the PR to be succinct and less than 65 characters
  • Add a milestone to the PR for the sprint that it is merged (i.e. add S47)
  • Tag the PR with the type of update: Bug, Build, Dependencies, Enhancement, New-Feature or Documentation
  • Tag the PR with Open source, Azure API for FHIR (CosmosDB or common code) or Azure Healthcare APIs (SQL or common code) to specify where this change is intended to be released.
  • Tag the PR with Schema Version backward compatible or Schema Version backward incompatible or Schema Version unchanged if this adds or updates Sql script which is/is not backward compatible with the code.
  • When changing or adding behavior, if your code modifies the system design or changes design assumptions, please create and include an ADR.
  • CI is green before merge Build Status
  • Review squash-merge requirements

Semver Change (docs)

Patch|Skip|Feature|Breaking (reason)

@fhibf Fernando Henrique Inocêncio Borba Ferreira (fhibf) added Enhancement Enhancement on existing functionality. No-Issue-Activity This issue is now considered stale and will be closed soon Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs No-PaaS-breaking-change No-ADR ADR not needed labels Oct 15, 2026
Comment thread src/Microsoft.Health.Fhir.Shared.Api/Features/Resources/Bundle/BundleHandler.cs Dismissed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The calculator tests contain a compilation error, empty payload fixtures, and incorrect boundary inputs.

4 open findings
What changed in this PR

Adds bundle complexity tracking to Microsoft FHIR Server’s processing statistics and latency metrics.

Changes:

  • Calculates complexity from operation counts, execution mode, and payload sizes.
  • Moves latency emission into the bundle handler and adds a complexity dimension.
  • Adds calculator tests and updates existing metric assertions.
File Description
src/​Microsoft.Health.Fhir.Shared.Api/​Microsoft.Health.Fhir.Shared.Api.projitems Registers new bundle classes; removes metric filter.
src/​Microsoft.Health.Fhir.Shared.Api/​Features/​Resources/​Bundle/​BundleHandlerStatistics.cs Includes complexity in statistics.
src/​Microsoft.Health.Fhir.Shared.Api/​Features/​Resources/​Bundle/​BundleHandlerParallelOperations.cs Uses extracted execution context.
src/​Microsoft.Health.Fhir.Shared.Api/​Features/​Resources/​Bundle/​BundleHandlerInternalOperationExecutionContext.cs Extracts operation context into a class.
src/​Microsoft.Health.Fhir.Shared.Api/​Features/​Resources/​Bundle/​BundleHandlerComplexityCalculator.cs Implements complexity scoring.
src/​Microsoft.Health.Fhir.Shared.Api/​Features/​Resources/​Bundle/​BundleHandler.cs Calculates complexity and emits latency.
src/​Microsoft.Health.Fhir.Shared.Api/​Features/​Filters/​Metrics/​BundleEndpointMetricEmitterAttribute.cs Removes endpoint latency filter.
src/​Microsoft.Health.Fhir.Shared.Api/​Controllers/​FhirController.cs Removes bundle metric attribute.
src/​Microsoft.Health.Fhir.Shared.Api.UnitTests/​Microsoft.Health.Fhir.Shared.Api.UnitTests.projitems Registers calculator and relocated tests.
src/​Microsoft.Health.Fhir.Shared.Api.UnitTests/​Features/​Resources/​Bundle/​FhirTransactionFailedExceptionTests.cs Relocates transaction exception tests.
src/​Microsoft.Health.Fhir.Shared.Api.UnitTests/​Features/​Resources/​Bundle/​BundleHandlerTests.cs Checks handler latency emission.
src/​Microsoft.Health.Fhir.Shared.Api.UnitTests/​Features/​Resources/​Bundle/​BundleHandlerStatisticsTests.cs Supplies complexity to statistics.
src/​Microsoft.Health.Fhir.Shared.Api.UnitTests/​Features/​Resources/​Bundle/​BundleHandlerComplexityCalculatorTests.cs Adds scoring and boundary tests.
src/​Microsoft.Health.Fhir.Shared.Api.UnitTests/​Features/​Filters/​Metrics/​MetricEmitterAttributeTests.cs Removes obsolete bundle filter test.
src/​Microsoft.Health.Fhir.Shared.Api.UnitTests/​Controllers/​FhirControllerTests.cs Removes obsolete attribute assertion.
src/​Microsoft.Health.Fhir.Core/​Models/​BundleComplexity.cs Defines four complexity levels.
src/​Microsoft.Health.Fhir.Core/​Logging/​Metrics/​Handlers/​DefaultBundleMetricHandler.cs Tags latency measurements with complexity.
src/​Microsoft.Health.Fhir.Core/​Logging/​Metrics/​BundleMetricNotification.cs Adds complexity and validates elapsed time.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

_profilesResolver,
_logger);
}
catch (InvalidOperationException e)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit - could combine the exception statements as the message is the same.

@fhibf

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Enhancement Enhancement on existing functionality. No-ADR ADR not needed No-Issue-Activity This issue is now considered stale and will be closed soon No-PaaS-breaking-change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants