Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

fix issues with reporting #131

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions controllers/installation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ var requeueAfter = time.Hour
// NodeEventsBatch is a batch of node events, meant to be gathered at a given
// moment in time and send later on to the metrics server.
type NodeEventsBatch struct {
NodesAdded []metrics.NodeEvent
NodesUpdated []metrics.NodeEvent
NodesRemoved []metrics.NodeRemovedEvent
NodesAdded []metrics.NodeEvent
NodesUpdated []metrics.NodeEvent
NodesRemoved []metrics.NodeRemovedEvent
FirstNodeAdded *metrics.NodeEvent
}

// InstallationReconciler reconciles a Installation object
Expand Down Expand Up @@ -122,7 +123,13 @@ func (r *InstallationReconciler) ReconcileNodeStatuses(ctx context.Context, in *
return nil, fmt.Errorf("failed to update node status: %w", err)
}
if isnew {
batch.NodesAdded = append(batch.NodesAdded, event)
if len(nodes.Items) == 1 {
// this is the first node, and so this is not a node added event but a firstNode added event
batch.FirstNodeAdded = &event
} else {
batch.NodesAdded = append(batch.NodesAdded, event)
}

continue
}
batch.NodesUpdated = append(batch.NodesUpdated, event)
Expand Down Expand Up @@ -160,13 +167,21 @@ func (r *InstallationReconciler) ReportNodesChanges(ctx context.Context, in *v1b
ctrl.LoggerFrom(ctx).Error(err, "failed to notify node removed")
}
}
if batch.FirstNodeAdded != nil {
if err := metrics.NotifyFirstNodeAdded(ctx, in.Spec.MetricsBaseURL, *batch.FirstNodeAdded); err != nil {
ctrl.LoggerFrom(ctx).Error(err, "failed to notify first node added")
}
}
}

// ReportInstallationChanges reports back to the metrics server if the installation status has changed.
func (r *InstallationReconciler) ReportInstallationChanges(ctx context.Context, before, after *v1beta1.Installation) {
if len(before.Status.State) == 0 || before.Status.State == after.Status.State {
return
}

fmt.Printf("beforeState: %q, afterState %q\n", before.Status.State, after.Status.State)

var err error
switch after.Status.State {
case v1beta1.InstallationStateInstalling:
Expand Down
15 changes: 15 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ type UpgradeSucceededEvent struct {
ClusterID string `json:"clusterID"`
}

// InstallationSucceededEvent event is send back home when the upgrade succeeds.
type InstallationSucceededEvent struct {
ClusterID string `json:"clusterID"`
}

// Hash returns the hash of the node.
func (n NodeEvent) Hash() (string, error) {
hasher := sha256.New()
Expand Down Expand Up @@ -105,6 +110,11 @@ func NotifyNodeAdded(ctx context.Context, baseURL string, ev NodeEvent) error {
return sendEvent(ctx, "NodeAdded", baseURL, ev)
}

// NotifyFirstNodeAdded notifies the metrics server that a node has been added.
func NotifyFirstNodeAdded(ctx context.Context, baseURL string, ev NodeEvent) error {
return sendEvent(ctx, "FirstNodeAdded", baseURL, ev)
}

// NotifyNodeRemoved notifies the metrics server that a node has been removed.
func NotifyNodeRemoved(ctx context.Context, baseURL string, ev NodeRemovedEvent) error {
return sendEvent(ctx, "NodeRemoved", baseURL, ev)
Expand All @@ -124,3 +134,8 @@ func NotifyUpgradeFailed(ctx context.Context, baseURL string, ev UpgradeFailedEv
func NotifyUpgradeSucceeded(ctx context.Context, baseURL string, ev UpgradeSucceededEvent) error {
return sendEvent(ctx, "UpgradeSucceeded", baseURL, ev)
}

// NotifyInstallationCompleted notifies the metrics server that an upgrade has started.
func NotifyInstallationCompleted(ctx context.Context, baseURL string, ev InstallationSucceededEvent) error {
return sendEvent(ctx, "InstallationCompleted", baseURL, ev)
}
Loading