How dynatrace/dynatrace-configuration-as-code-core works
Project type and purpose
• This is a Go library (not an end-user application) that provides reusable building blocks for “Configuration as Code” tools targeting the Dynatrace API.
• It offers two layers of clients:
• api/clients – low-level, one-to-one Go wrappers around REST calls.
• clients – higher-level, “smarter” abstractions (CRUD + Upsert) that build on api/clients to simplify common use cases.
File structure
• Top-level packages:
• api/… – basic clients, REST helpers (api/rest), authentication (api/auth), response handling.
• clients/… – factory, smart clients per domain (automation, buckets, documents, etc.).
• gen/… – auto-generated OpenAPI client code for account_management (not hand-written).
• internal/… – shared/internal utilities (pointer helpers).
• testutils/… – helper server/context for tests.
• tools/… – developer scripts (lint, license checks, git hooks).
• Configuration & CI files: .github/workflows, Makefile, sonar, golangci lint, etc., indicate a robust CI/CD and code-quality pipeline.
README for additional insights
• Describes purpose: not a general Dynatrace client, but a helper for Config-as-Code tools (e.g., Monaco CLI, Terraform provider).
• Shows usage: clients.Factory → WithEnvironmentURL/WithOAuthCredentials → factory.BucketClient() → .Get() → api.DecodeJSON.
• Mentions optional logging via logr and HTTPListener injection.
Main components & interactions (
a. Clients.Factory
– Entry point: configures base URL, auth, optional HTTPListener & logger.
b. “Smarter” clients (clients/…)
– Depend on: Factory → api/clients lower layer.
– Offer: CRUD + Upsert, domain-specific logic (automation, buckets, documents, openpipeline, segments, SLO).
c. “Basic” API clients (api/clients/…)
– Wrap: HTTP calls (api/rest package) to Dynatrace endpoints.
– Include auth/token management (api/auth).
d. REST layer (api/rest)
– Core HTTP logic: concurrency, retries, rate limiting, listener callbacks, request/response parsing.
e. Code-generated layer (gen)
– Provides strongly typed models & client for account_management domain.
– Used by clients if account_management support is needed.
f. External Dependencies & Services
– Dynatrace API (external HTTP service).
– logr (logging interface).
– Context propagation for logging & cancellation.
g. Developer tooling & tests
– testutils: in-process HTTP server for unit tests.
– tools: formatting, license, hooks.
Architectural patterns & design principles
• Layered architecture:
• Presentation/API‐wrapper (api/clients)
• Business/service layer (clients/…)
• Infrastructure/HTTP concerns (api/rest)
• Dependency injection: Factory configures clients with auth, URL, logger, HTTPListener.
• Code generation: gen/… isolates spec-driven code from handwritten.
• Internal package for non-public utilities.
• Testability: testutils to spin up fake HTTP endpoints; HTTPListener for observability.
2. Inside it, partition into three horizontal layers:
Layer 1 (top): clients.Factory & “Smarter Clients” (clients/*)
Layer 2 (middle): Basic API Clients (api/clients/*)
Layer 3 (bottom): REST & Auth (api/rest, api/auth)
6. Annotate:
• Auth flow: api/auth → token.go → REST calls include token header.
• HTTPListener: plug into REST layer.
• Logging: propagate via context.
• Rounded rectangles for packages.