Skip to content

Commit

Permalink
lxd/api_metrics: Filter Warnings/Operation queries by node
Browse files Browse the repository at this point in the history
Signed-off-by: hamistao <[email protected]>
  • Loading branch information
hamistao committed Oct 22, 2024
1 parent a6a2b2a commit 471cc6e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lxd/api_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func metricsGet(d *Daemon, r *http.Request) response.Response {
}

// Register internal metrics.
intMetrics = internalMetrics(ctx, s.StartTime, tx)
intMetrics = internalMetrics(ctx, s.ServerName, s.StartTime, tx)
return nil
})
if err != nil {
Expand Down Expand Up @@ -378,18 +378,21 @@ func getFilteredMetrics(s *state.State, r *http.Request, compress bool, metricSe
return response.SyncResponsePlain(true, compress, metricSet.String())
}

func internalMetrics(ctx context.Context, daemonStartTime time.Time, tx *db.ClusterTx) *metrics.MetricSet {
func internalMetrics(ctx context.Context, nodeName string, daemonStartTime time.Time, tx *db.ClusterTx) *metrics.MetricSet {
out := metrics.NewMetricSet(nil)
var warnings []dbCluster.Warning

warnings, err := dbCluster.GetWarnings(ctx, tx.Tx())
warnings, err := dbCluster.GetWarnings(ctx, tx.Tx(), dbCluster.WarningFilter{Node: &nodeName})
if err != nil {
logger.Warn("Failed to get warnings", logger.Ctx{"err": err})
} else {
// Total number of warnings
out.AddSamples(metrics.WarningsTotal, metrics.Sample{Value: float64(len(warnings))})
}

operations, err := dbCluster.GetOperations(ctx, tx.Tx())
// Create local variable to get a pointer.
nodeID := tx.GetNodeID()
operations, err := dbCluster.GetOperations(ctx, tx.Tx(), dbCluster.OperationFilter{NodeID: &nodeID})
if err != nil {
logger.Warn("Failed to get operations", logger.Ctx{"err": err})
} else {
Expand Down

0 comments on commit 471cc6e

Please sign in to comment.