A high-level breakdown of how the VictoriaMetrics metrics exporter is structured internally.
- Single binary – UI assets are embedded; the HTTP server defaults to localhost (configurable via
-addrand auto-fallback to a free port). - Privacy-first – the pipeline obfuscates data as it streams instead of handling temporary plaintext copies.
- Stateless – no configuration files or databases; everything is supplied per-run.
- Predictable UX – the same 6-step flow as other VictoriaMetrics utilities.
| Layer | Package | Responsibility |
|---|---|---|
| Presentation | internal/server |
Hosts the HTTP server, serves static assets, exposes REST endpoints to the UI. |
| Presentation | internal/importer/server |
Standalone VMImport UI & API for uploading bundles back into VictoriaMetrics. |
| Application | internal/application/services |
Orchestrates validation, discovery, sampling, and export workflows. |
| Infrastructure | internal/infrastructure/vm |
VictoriaMetrics client (query, export APIs, auth, multitenancy). |
| Infrastructure | internal/infrastructure/obfuscation |
Deterministic obfuscation for IPs/jobs/custom labels. |
| Infrastructure | internal/infrastructure/archive |
Streams export data, writes metadata, generates ZIP + checksum. |
| Domain | internal/domain |
Shared types/configs used across the stack. |
- Vanilla JS + HTML/CSS, compiled and embedded via
go:embed. - Implements the wizard, validation states, and progress updates.
- Communicates only with the local server (
/api/*endpoints).
- Go 1.21+ HTTP server using the standard library.
- Defaults to
localhost:8080(exporter) and0.0.0.0:8081(importer); falls back to a free port when busy. - Provides REST APIs mirroring other VictoriaMetrics tools.
Browser
↓ (REST)
internal/server (HTTP handler)
↓
application/services.VMService
↓
infrastructure/vm.Client ───→ VictoriaMetrics API
↓ ↑
application/services.ExportService │
↓ │
infrastructure/obfuscation.Manager │
↓ │
infrastructure/archive.Writer ──────────────┘
↓
ZIP archive → browser download
- Batching: auto-selects 30s/1m/5m windows (or custom interval) per time range; minimum batch interval 30s.
- Metric step: defaults to the same 30s/1m/5m cadence unless overridden via
metric_step_seconds. - Fallback: if
/api/v1/exportreturns 404/missing route, transparently switches toquery_rangewith normalized/rw/prometheus→/prometheuspaths for VMAuth. - Staging:
/api/fs/checkcreates/validates staging directories and write access; job metadata exposes the staging path. - Job manager: up to 3 concurrent exports, ETA/progress tracking, cancellation, retention window for finished jobs.
- Obfuscation: instance/job/custom labels applied consistently to samples and exports; deterministic maps are embedded in archive metadata;
metadata.json+README.txtaccompanymetrics.jsonlin the ZIP along with SHA256.
| Endpoint | Purpose |
|---|---|
POST /api/validate |
Checks reachability, auth, and returns detected VM flavour + version. |
| `POST /api/discover` | Finds available components, per-job series estimates, and jobs via `vm_app_version`. |
| POST /api/sample | Fetches preview metrics (up to a safe limit) for UI confirmation. |
| POST /api/export | Legacy synchronous export used by CLI tools. Still available for compatibility. |
| POST /api/export/start | Starts a batched export job, including optional staging_dir and metric_step_seconds hints, and returns job meta (batches/ETA/staging path). |
| GET /api/export/status | Polls the state of a running export job (progress, ETA, final archive metadata). |
| GET /api/download?path=… | Returns the generated ZIP file. |
| GET /api/fs/list | Lists directories for staging selection with basic write hints. |
| POST /api/fs/check | Validates/creates a staging directory and write-ability. |
| POST /api/export/cancel | Cancels a running export job. |
| GET /api/config | Returns UI defaults (version, recommended staging dir, OS hints). |
All endpoints accept/return JSON with error details suitable for UI presentation.
- IPs – replaced with
777.777.X.Y, retaining port numbers and component grouping. - Jobs – renamed to
<component>-job-<n>while keeping the original component prefix. - Custom labels – user-provided keys; mappings kept in memory for the session, not persisted.
- Sample previews –
/api/sampleresponses and export previews reuse the obfuscator so the UI never shows raw instances/jobs once obfuscation is enabled. - Deterministic – the same input within a session maps to the same output so support can correlate metrics.
- Credentials remain in memory only for the duration of the call and are never written to disk.
- The HTTP server binds to
localhostand random ports to lower the risk surface. - Temporary files are removed immediately after the bundle is downloaded or when the process exits.
- Unit tests cover domain logic, VM API client edge cases, obfuscation permutations, and archive writing.
- Integration tests spin up VictoriaMetrics flavours through
local-test-env. - Playwright E2E suites exercise the complete wizard flow, ensuring API contracts stay stable.
VMImporter is purposely isolated from the exporter codebase to minimise coupling: aside from sharing the repo and build tooling it does not import exporter packages. Its flow is intentionally short:
Browser (drop zone + endpoint form)
↓ /api/upload (multipart form)
internal/importer/server
↓
sendToEndpoint → VictoriaMetrics /api/v1/import
The UI mirrors vmgather's connection card but introduces tenant/account ID fields and a drag-and-drop area for .jsonl/.zip bundles. The backend treats uploaded data as opaque bytes and re-streams it to VictoriaMetrics, reusing the same auth/TLS toggles. Tests reuse local-test-env so uploads can be validated against real vmselect/vminsert setups before releasing.
- Bundle ingestion: accepts
.zip(extractsmetrics.jsonl/metadata.json) or raw.jsonl; rejects archives without metrics. - Chunked streaming: uploads in ~512KB chunks to
/api/v1/import, with progress reporting, byte counters, and resumable offsets on failure. - Resume:
/api/import/resumecontinues a failed job from the saved offset and cached bundle path. - Retention: optional
drop_olddrops points older than the target’s retention (fetched via/api/v1/status/tsdb); warnings surface via/api/analyze. - Tenant isolation: always forwards tenant/account via
X-Vm-TenantIDand supports Basic/custom header auth plus TLS skip. - Verification: post-upload sampling (
/api/v1/series+ time window derived from metadata) to confirm visibility; status is exposed via/api/import/status.