Skip to content

Update go-json-schema-generate - #7678

Draft
swiatekm wants to merge 6 commits into
mainfrom
update/go-json-schema-generate
Draft

Update go-json-schema-generate#7678
swiatekm wants to merge 6 commits into
mainfrom
update/go-json-schema-generate

Conversation

@swiatekm

Copy link
Copy Markdown
Member

What is the problem this PR solves?

// Please do not just reference an issue. Explain WHAT the problem this PR solves here.

How does this PR solve the problem?

// Explain HOW you solved the problem in your code. It is possible that during PR reviews this changes and then this section should be updated.

How to test this PR locally

Design Checklist

  • I have ensured my design is stateless and will work when multiple fleet-server instances are behind a load balancer.
  • I have or intend to scale test my changes, ensuring it will work reliably with 100K+ agents connected.
  • I have included fail safe mechanisms to limit the load on fleet-server: rate limiting, circuit breakers, caching, load shedding, etc.

Checklist

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool

Related issues

swiatekm and others added 6 commits August 20, 2026 17:04
…c708d18d6ca2

This version generates time.Time instead of string for JSON Schema
"format": "date-time" fields, aligning with Go's time semantics.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
go fix in Go 1.26 converts string JSON fields with time semantics to
time.Time. Update all code that was assigning strings to these fields
or comparing them against empty strings.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Update unit tests and zero-time guard after go fix converted model time
fields from string to time.Time. Truncate all test-created timestamps to
millisecond precision so stored and retrieved values match after the ES
round-trip (Elasticsearch date fields only preserve millisecond precision).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fix all 58 golangci-lint issues introduced by the elastic dependency
update, spanning errcheck (type assertions in testify mocks and monitor
options), staticcheck (De Morgan's law, fmt.Fprintf, embedded field
selectors, tagged switch), gosec (G101/G115/G117/G602 false positives),
noctx (net.Dial/Listen/httptest.NewRequest without context), prealloc,
misspell, nolintlint (stale directives), and gocheckcompilerdirectives
(go:fix inline is a valid Go 1.26 directive).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ization

Go's encoding/json does not omit zero time.Time struct values with omitempty
(only basic types and nil pointers are omitted). After the schema-generate
upgrade changed date-time fields from string to time.Time, optional Agent
fields like unenrolled_at serialized as "0001-01-01T00:00:00Z" instead of
being absent from the document.

This caused Kibana Fleet to treat freshly enrolled agents as unenrolled
(non-null unenrolled_at), so the E2E TestDockerAgent test timed out after
30 minutes waiting for the managing agent to appear online.

Fix: change the 8 optional time.Time fields in model.Agent to *time.Time.
A nil pointer is correctly omitted with omitempty. Add a note in main.go
explaining why manual post-processing of schema.go is needed after
schema regeneration.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…generate

Add dev-tools/fixschema/main.go post-processing tool that runs after
schema-generate to convert optional time.Time fields in model.Agent to
*time.Time. The tool is invoked from main.go go:generate directives,
replacing the manual NOTE comment. go fmt is run on schema.go before
fixschema so the generated file uses tab indentation that matches the
replacement pattern.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 21, 2026 10:26
@mergify

mergify Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

This pull request does not have a backport label. Could you fix it @swiatekm? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-./d./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates go-json-schema-generate, migrates date-time handling to time.Time, and modernizes Go 1.26 compatibility.

Changes:

  • Adds schema post-processing for optional timestamps.
  • Updates timestamp consumers, persistence, and tests.
  • Refreshes Go APIs, atomics, Elasticsearch calls, and lint configuration.

Reviewed changes

Copilot reviewed 58 out of 59 changed files in this pull request and generated 2 comments.

Show a summary per file
File Reviewed change or final finding
main.go Adds schema post-processing generation.
internal/pkg/throttle/throttle_test.go Preallocates test token storage.
internal/pkg/testing/setup.go Updates Elasticsearch client usage.
internal/pkg/testing/port.go Updates lint annotations.
internal/pkg/testing/cache/cache.go Annotates mock assertions.
internal/pkg/testing/actions.go Uses typed timestamps.
internal/pkg/server/remote_es_output_integration_test.go Uses strings.Cut.
internal/pkg/server/namespaces_integration_test.go Updates typed expiration handling.
internal/pkg/server/fleet_integration_test.go Uses typed error matching.
internal/pkg/server/agent_integration_test.go Uses contextual listeners.
internal/pkg/scheduler/scheduler.go Removes obsolete conversion suppression.
internal/pkg/profile/profile_test.go Uses contextual listeners and requests.
internal/pkg/policy/policy_output.go Uses typed retirement timestamps.
internal/pkg/policy/policy_output_integration_test.go Updates timestamp fixtures.
internal/pkg/monitor/subscription_monitor.go Uses typed atomic counters.
internal/pkg/monitor/monitor.go Makes option application defensive.
internal/pkg/monitor/mock/monitor.go Annotates mock assertions.
internal/pkg/model/schema.go Moderate (3 votes): optional zero-valued time.Time fields are not omitted during JSON marshaling; preserve pointers or add zero-value omission.
internal/pkg/model/ext.go Updates timestamp helpers.
internal/pkg/model/ext_test.go Updates API-key timestamp fixtures.
internal/pkg/logger/http.go Uses typed atomic counters.
internal/pkg/logger/ecs/ecs.go Corrects comment spelling.
internal/pkg/limit/listener_test.go Uses contextual dialing.
internal/pkg/limit/limiter_test.go Adds mock assertion annotation.
internal/pkg/gc/actions_integration_test.go Adds preallocation annotation.
internal/pkg/file/file.go Simplifies status logic.
internal/pkg/file/cbor/chunk.go Updates conversion annotations.
internal/pkg/es/error.go Simplifies error unwrapping.
internal/pkg/dl/policies_integration_test.go Uses typed policy timestamps.
internal/pkg/dl/migration_integration_test.go Uses shared typed test time.
internal/pkg/dl/enrollment_api_key.go Documents intentional marshaling.
internal/pkg/dl/enrollment_api_key_integration_test.go Uses typed enrollment timestamps.
internal/pkg/dl/agent_integration_test.go Uses typed agent timestamps.
internal/pkg/dl/actions.go Updates Elasticsearch client calls.
internal/pkg/dl/action_results.go Updates action-result timestamp persistence.
internal/pkg/dl/action_results_integration_test.go Updates action timestamp fixtures.
internal/pkg/danger/buf.go Annotates safe byte conversion.
internal/pkg/config/output.go Uses direct formatted writes.
internal/pkg/config/logging.go Simplifies boolean logic.
internal/pkg/config/instrumentation_test.go Updates lint annotations.
internal/pkg/checkin/bulk_integration_test.go Updates typed agent timestamps.
internal/pkg/bulk/opMulti_integration_test.go Preallocates bulk operations.
internal/pkg/api/utils.go Repositions compiler directives.
internal/pkg/api/handleUpload.go Uses errors.AsType.
internal/pkg/api/handleOpAMP.go Uses typed enrollment timestamps.
internal/pkg/api/handleOpAMP_test.go Updates typed audit timestamp fixtures.
internal/pkg/api/handleEnroll.go Updates typed agent timestamp handling.
internal/pkg/api/handleCheckin.go Moderate (4 votes): guard zero Policy.Timestamp before formatting to avoid sending a fabricated creation time.
internal/pkg/api/handleArtifacts.go Uses structured timestamp logging.
internal/pkg/api/handleAck.go Uses typed result timestamps and errors.
internal/pkg/api/handleAck_test.go Updates timestamp assertions.
internal/pkg/api/error.go Uses errors.AsType.
internal/pkg/api/apiVersion_test.go Uses contextual HTTP requests.
internal/pkg/action/dispatcher.go Uses typed rollout timestamps.
internal/pkg/action/dispatcher_test.go Updates typed timestamp fixtures.
dev-tools/go.sum Updates dependency checksums.
dev-tools/go.mod Updates the schema generator dependency.
dev-tools/fixschema/main.go Adds optional-agent timestamp post-processing.
.golangci.yml Adjusts lint exclusions.
Suppressed comments (1)

dev-tools/fixschema/main.go:24

  • Only Agent fields are rewritten here, but the generator now emits other optional date-time properties (for example Action.Expiration/StartTime/Timestamp, ActionResult.StartedAt/CompletedAt, Policy.Timestamp, and ToRetireAPIKeyIdsItems.RetiredAt) as value time.Time. encoding/json does not omit a zero struct even with omitempty, so marshaling an action/result without those values now writes 0001-01-01T00:00:00Z to Elasticsearch instead of omitting the fields. Please cover all optional date-time fields (or add equivalent custom omission handling), and update the affected call sites.
// agentOptionalTimeFields are the time.Time fields in model.Agent that must be
// *time.Time so that omitempty correctly omits them when unset.
var agentOptionalTimeFields = []string{
	"AuditUnenrolledTime",
	"LastCheckin",

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

resp := Action{
AgentId: agent.Id,
CreatedAt: pp.Policy.Timestamp,
CreatedAt: pp.Policy.Timestamp.Format(time.RFC3339Nano),

// Date/time the action was completed
CompletedAt string `json:"completed_at,omitempty"`
CompletedAt time.Time `json:"completed_at,omitempty"`
@mergify

mergify Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

This pull request is now in conflicts. Could you fix it @swiatekm? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b update/go-json-schema-generate upstream/update/go-json-schema-generate
git merge upstream/main
git push upstream update/go-json-schema-generate

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants