offline license utilization reporting (#25844)

Nomad Enterprise users operating in air-gapped or otherwise secured environments
don't want to send license reporting metrics directly from their
servers. Implement manual/offline reporting by periodically recording usage
metrics snapshots in the state store, and providing an API and CLI by which
cluster administrators can download the snapshot for review and out-of-band
transmission to HashiCorp.

This is the CE portion of the work required for implemention in the Enterprise
product. Nomad CE does not perform utilization reporting.

Ref: https://github.com/hashicorp/nomad-enterprise/pull/2673
Ref: https://hashicorp.atlassian.net/browse/NMD-68
Ref: https://go.hashi.co/rfc/nmd-210
This commit is contained in:
Tim Gross
2025-05-14 09:51:13 -04:00
committed by GitHub
parent 79d35f072a
commit 8a5a057d88
21 changed files with 380 additions and 14 deletions

View File

@@ -8,6 +8,7 @@ import (
"errors"
"io"
"net/http"
"net/url"
"strconv"
"strings"
"time"
@@ -475,3 +476,28 @@ func (op *Operator) UpgradeCheckVaultWorkloadIdentity(q *QueryOptions) (*VaultWo
}
return &resp, qm, nil
}
type OperatorUtilizationOptions struct {
TodayOnly bool
}
type OperatorUtilizationSnapshotResponse struct {
// Bundle is the JSON serialized utilization reporting bundle.
Bundle []byte
WriteMeta
}
// Utilization retrieves a utilization reporting bundle (Nomad Enterprise only).
func (op *Operator) Utilization(opts *OperatorUtilizationOptions, w *WriteOptions) (*OperatorUtilizationSnapshotResponse, *WriteMeta, error) {
resp := &OperatorUtilizationSnapshotResponse{}
v := url.Values{}
if opts.TodayOnly {
v.Add("today", "true")
}
wm, err := op.c.post("/v1/operator/utilization?"+v.Encode(), nil, resp, w)
if err != nil {
return nil, nil, err
}
return resp, wm, nil
}