Skip to content

chore: Expand logging in ADCS Post-Process - BED-8305#2791

Merged
StephenHinck merged 2 commits into
mainfrom
BED-8305
May 18, 2026
Merged

chore: Expand logging in ADCS Post-Process - BED-8305#2791
StephenHinck merged 2 commits into
mainfrom
BED-8305

Conversation

@StephenHinck

@StephenHinck StephenHinck commented May 18, 2026

Copy link
Copy Markdown
Contributor

Description

Expands logging in ADCS post-processing functions to make identification of bottlenecks significantly faster

Motivation and Context

Resolves BED-8305

Why is this change required? What problem does it solve?

How Has This Been Tested?

I have been running multiple performance validations utilizing these log lines locally.

Screenshots (optional):

Types of changes

  • Chore (a change that does not modify the application functionality)

Checklist:

Summary by CodeRabbit

  • Chores
    • Added performance measurement and instrumentation to certificate processing and cache-building to improve observability of ADCS and related flows.
  • Style
    • Minor internal string-building changes to error and SQL generation routines for clearer formatting (no behavioral changes).

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 66feedb9-59da-4400-93ed-c6e8baf20f43

📥 Commits

Reviewing files that changed from the base of the PR and between 7557889 and 2a9af2f.

📒 Files selected for processing (2)
  • cmd/api/src/services/upload/streamdecoder.go
  • packages/go/schemagen/generator/sql.go
✅ Files skipped from review due to trivial changes (2)
  • packages/go/schemagen/generator/sql.go
  • cmd/api/src/services/upload/streamdecoder.go

📝 Walkthrough

Walkthrough

Adds measurement wrappers (measure.ContextMeasure / ContextMeasureWithThreshold) to ADCS processing functions and cache-building loops; separately replaces sb.WriteString(fmt.Sprintf(...)) with fmt.Fprintf(&sb, ...) in two string-building sites.

Changes

ADCS Observability Instrumentation

Layer / File(s) Summary
ADCS processing function instrumentation
packages/go/analysis/ad/adcs.go
PostADCS and pre-process steps now defer measure.ContextMeasure; processEnterpriseCAWithValidCertChainToDomain instruments each SubmitReader (GoldenCert and PostADCSESC* variants) with measure.ContextMeasureWithThreshold including enterprise_ca_id.
Cache building loop instrumentation
packages/go/analysis/ad/adcscache.go
ADCSCache.BuildCache creates and invokes ContextMeasure scopes around cert template, enterprise CA, and domain population loops (measure created before loop phase and invoked after).

String Builder / SQL Emission Changes

Layer / File(s) Summary
Upload stream decoder message formatting
cmd/api/src/services/upload/streamdecoder.go
ValidationReport.Error() and formatSchemaValidationError() now use fmt.Fprintf(&sb, ...) instead of sb.WriteString(fmt.Sprintf(...)) to write validation/critical error messages.
Schema SQL generator rendering
packages/go/schemagen/generator/sql.go
GenerateExtensionSQL now writes formatted SQL directly to the strings.Builder using fmt.Fprintf(&sb, ...) for the header, DO $$ block emissions, and relationship upserts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • cweidenkeller
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically identifies the main change: expanding logging in ADCS post-processing functions, with an associated ticket reference.
Description check ✅ Passed The description covers the main aspects: a clear description of changes, motivation (faster bottleneck identification), testing details, type of change classification, and a completed checklist with all required items marked.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch BED-8305

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot added the go Pull requests that update go code label May 18, 2026

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
packages/go/analysis/ad/adcscache.go (1)

97-104: ⚡ Quick win

Group measure initializations in a single var block and expand abbreviated naming.

These three measure handles are related and can be hoisted/grouped together; also prefer a richer name than ecaMeasure (e.g., enterpriseCAMeasure) for consistency.

♻️ Proposed refactor
-		certTemplateMeasure := measure.ContextMeasure(
+		var (
+			certTemplateMeasure = measure.ContextMeasure(
 			ctx,
 			slog.LevelInfo,
 			"BuildCache cert template loop",
 			attr.Namespace("analysis"),
 			attr.Function("BuildCache.CertTemplates"),
 			attr.Scope("routine"),
-		)
+			)
+			enterpriseCAMeasure = measure.ContextMeasure(
+				ctx,
+				slog.LevelInfo,
+				"BuildCache enterprise CA loop",
+				attr.Namespace("analysis"),
+				attr.Function("BuildCache.EnterpriseCAs"),
+				attr.Scope("routine"),
+			)
+			domainMeasure = measure.ContextMeasure(
+				ctx,
+				slog.LevelInfo,
+				"BuildCache domain loop",
+				attr.Namespace("analysis"),
+				attr.Function("BuildCache.Domains"),
+				attr.Scope("routine"),
+			)
+		)
@@
-		ecaMeasure := measure.ContextMeasure(
-			ctx,
-			slog.LevelInfo,
-			"BuildCache enterprise CA loop",
-			attr.Namespace("analysis"),
-			attr.Function("BuildCache.EnterpriseCAs"),
-			attr.Scope("routine"),
-		)
@@
-		ecaMeasure()
+		enterpriseCAMeasure()
@@
-		domainMeasure := measure.ContextMeasure(
-			ctx,
-			slog.LevelInfo,
-			"BuildCache domain loop",
-			attr.Namespace("analysis"),
-			attr.Function("BuildCache.Domains"),
-			attr.Scope("routine"),
-		)

As per coding guidelines: “Group variable initializations in a var ( ... ) block and hoist them to the top of the function when possible” and “Prefer rich variable names, for example: databaseInterface instead of di or dbi.”

Also applies to: 146-153, 212-219

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/go/analysis/ad/adcscache.go` around lines 97 - 104, Hoist and group
the related ContextMeasure initializations into a single var (...) block at the
top of the BuildCache.CertTemplates function and replace the abbreviated
ecaMeasure name with a clearer enterpriseCAMeasure (and similarly expand any
other abbreviated measure names), e.g., declare certTemplateMeasure,
enterpriseCAMeasure, and any other related measures together; ensure each
measure still calls measure.ContextMeasure(...) with the same attributes and use
the new variable names throughout the function. Also apply the same grouping and
renaming pattern to the other similar measure sets in this file so all related
measures are declared in var blocks with descriptive names and referenced
consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/go/analysis/ad/adcscache.go`:
- Around line 97-104: Hoist and group the related ContextMeasure initializations
into a single var (...) block at the top of the BuildCache.CertTemplates
function and replace the abbreviated ecaMeasure name with a clearer
enterpriseCAMeasure (and similarly expand any other abbreviated measure names),
e.g., declare certTemplateMeasure, enterpriseCAMeasure, and any other related
measures together; ensure each measure still calls measure.ContextMeasure(...)
with the same attributes and use the new variable names throughout the function.
Also apply the same grouping and renaming pattern to the other similar measure
sets in this file so all related measures are declared in var blocks with
descriptive names and referenced consistently.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 17c78755-5bb8-429f-82eb-81fa0b5b9710

📥 Commits

Reviewing files that changed from the base of the PR and between 36c383e and 7557889.

📒 Files selected for processing (2)
  • packages/go/analysis/ad/adcs.go
  • packages/go/analysis/ad/adcscache.go

@StephenHinck StephenHinck enabled auto-merge (squash) May 18, 2026 23:41
@StephenHinck StephenHinck merged commit b901fdf into main May 18, 2026
13 checks passed
@StephenHinck StephenHinck deleted the BED-8305 branch May 18, 2026 23:44
@github-actions github-actions Bot locked and limited conversation to collaborators May 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants