Skip to content

Commit

Permalink
Log MIWI/SP install type to AsyncQoS; also log successful cluster del…
Browse files Browse the repository at this point in the history
…etions (#3934)

* Add terminal-state log and metrics to successful cluster deletion operations.

* ARO-7841: Add "clusterIdentity" field to AsyncQoS logs
  • Loading branch information
ventifus authored and s-fairchild committed Feb 19, 2025
1 parent 1dd174d commit 33d7f00
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 33 deletions.
24 changes: 18 additions & 6 deletions pkg/backend/openshiftcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ func (ocb *openShiftClusterBackend) handle(ctx context.Context, log *logrus.Entr
// and stop monitoring the cluster.
// TODO: Provide better communication between RP and Monitor
time.Sleep(time.Until(t.Add(time.Second * time.Duration(monitorDeleteWaitTimeSec))))
return ocb.dbOpenShiftClusters.Delete(ctx, doc)
err := ocb.dbOpenShiftClusters.Delete(ctx, doc)
ocb.asyncOperationResultLog(log, doc, doc.OpenShiftCluster.Properties.ProvisioningState, err)
ocb.emitMetrics(log, doc, api.ProvisioningStateDeleting, api.ProvisioningStateFailed, err)
ocb.emitProvisioningMetrics(doc, api.ProvisioningStateFailed)
return err
}

return fmt.Errorf("unexpected provisioningState %q", doc.OpenShiftCluster.Properties.ProvisioningState)
Expand Down Expand Up @@ -313,7 +317,7 @@ func (ocb *openShiftClusterBackend) endLease(ctx context.Context, log *logrus.En
if err != nil {
return err
}
ocb.asyncOperationResultLog(log, initialProvisioningState, backendErr)
ocb.asyncOperationResultLog(log, doc, initialProvisioningState, backendErr)
ocb.emitMetrics(log, doc, operationType, provisioningState, backendErr)
ocb.emitProvisioningMetrics(doc, provisioningState)
}
Expand All @@ -337,11 +341,19 @@ func (ocb *openShiftClusterBackend) endLease(ctx context.Context, log *logrus.En
return err
}

func (ocb *openShiftClusterBackend) asyncOperationResultLog(log *logrus.Entry, initialProvisioningState api.ProvisioningState, backendErr error) {
func (ocb *openShiftClusterBackend) asyncOperationResultLog(log *logrus.Entry, doc *api.OpenShiftClusterDocument, initialProvisioningState api.ProvisioningState, backendErr error) {
clusterIdentity := unknown
if doc.OpenShiftCluster.Properties.PlatformWorkloadIdentityProfile != nil {
clusterIdentity = clusterIdentityManagedIdMetricName
} else if doc.OpenShiftCluster.Properties.ServicePrincipalProfile != nil {
clusterIdentity = clusterIdentityServicePrincipalMetricName
}

log = log.WithFields(logrus.Fields{
"LOGKIND": "asyncqos",
"resultType": utillog.SuccessResultType,
"operationType": initialProvisioningState.String(),
"LOGKIND": "asyncqos",
"resultType": utillog.SuccessResultType,
"operationType": initialProvisioningState.String(),
"clusterIdentity": clusterIdentity,
})

if backendErr == nil {
Expand Down
63 changes: 36 additions & 27 deletions pkg/backend/openshiftcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,10 @@ func TestAsyncOperationResultLog(t *testing.T) {
},
wantEntries: []map[string]types.GomegaMatcher{
{
"LOGKIND": gomega.Equal("asyncqos"),
"operationType": gomega.Equal("Succeeded"),
"resultType": gomega.Equal(utillog.SuccessResultType),
"LOGKIND": gomega.Equal("asyncqos"),
"operationType": gomega.Equal("Succeeded"),
"resultType": gomega.Equal(utillog.SuccessResultType),
"clusterIdentity": gomega.Equal(clusterIdentityServicePrincipalMetricName),
},
},
},
Expand All @@ -516,10 +517,11 @@ func TestAsyncOperationResultLog(t *testing.T) {
},
wantEntries: []map[string]types.GomegaMatcher{
{
"LOGKIND": gomega.Equal("asyncqos"),
"operationType": gomega.Equal("Failed"),
"resultType": gomega.Equal(utillog.UserErrorResultType),
"errorDetails": gomega.ContainSubstring("This is a user error result type"),
"LOGKIND": gomega.Equal("asyncqos"),
"operationType": gomega.Equal("Failed"),
"resultType": gomega.Equal(utillog.UserErrorResultType),
"clusterIdentity": gomega.Equal(clusterIdentityServicePrincipalMetricName),
"errorDetails": gomega.ContainSubstring("This is a user error result type"),
}},
},
{
Expand All @@ -535,10 +537,11 @@ func TestAsyncOperationResultLog(t *testing.T) {
},
wantEntries: []map[string]types.GomegaMatcher{
{
"LOGKIND": gomega.Equal("asyncqos"),
"operationType": gomega.Equal("Failed"),
"resultType": gomega.Equal(utillog.ServerErrorResultType),
"errorDetails": gomega.ContainSubstring("This is a server error result type"),
"LOGKIND": gomega.Equal("asyncqos"),
"operationType": gomega.Equal("Failed"),
"resultType": gomega.Equal(utillog.ServerErrorResultType),
"clusterIdentity": gomega.Equal(clusterIdentityServicePrincipalMetricName),
"errorDetails": gomega.ContainSubstring("This is a server error result type"),
}},
},
{
Expand All @@ -552,9 +555,10 @@ func TestAsyncOperationResultLog(t *testing.T) {
),
wantEntries: []map[string]types.GomegaMatcher{
{
"LOGKIND": gomega.Equal("asyncqos"),
"operationType": gomega.Equal("Failed"),
"resultType": gomega.Equal(utillog.ServerErrorResultType),
"LOGKIND": gomega.Equal("asyncqos"),
"operationType": gomega.Equal("Failed"),
"resultType": gomega.Equal(utillog.ServerErrorResultType),
"clusterIdentity": gomega.Equal(clusterIdentityServicePrincipalMetricName),
},
},
},
Expand All @@ -569,9 +573,10 @@ func TestAsyncOperationResultLog(t *testing.T) {
),
wantEntries: []map[string]types.GomegaMatcher{
{
"LOGKIND": gomega.Equal("asyncqos"),
"operationType": gomega.Equal("Failed"),
"resultType": gomega.Equal(utillog.UserErrorResultType),
"LOGKIND": gomega.Equal("asyncqos"),
"operationType": gomega.Equal("Failed"),
"resultType": gomega.Equal(utillog.UserErrorResultType),
"clusterIdentity": gomega.Equal(clusterIdentityServicePrincipalMetricName),
},
},
},
Expand All @@ -585,9 +590,10 @@ func TestAsyncOperationResultLog(t *testing.T) {
),
wantEntries: []map[string]types.GomegaMatcher{
{
"LOGKIND": gomega.Equal("asyncqos"),
"operationType": gomega.Equal("Failed"),
"resultType": gomega.Equal(utillog.ServerErrorResultType),
"LOGKIND": gomega.Equal("asyncqos"),
"operationType": gomega.Equal("Failed"),
"resultType": gomega.Equal(utillog.ServerErrorResultType),
"clusterIdentity": gomega.Equal(clusterIdentityServicePrincipalMetricName),
},
},
},
Expand All @@ -599,9 +605,10 @@ func TestAsyncOperationResultLog(t *testing.T) {
),
wantEntries: []map[string]types.GomegaMatcher{
{
"LOGKIND": gomega.Equal("asyncqos"),
"operationType": gomega.Equal("Failed"),
"resultType": gomega.Equal(utillog.ServerErrorResultType),
"LOGKIND": gomega.Equal("asyncqos"),
"operationType": gomega.Equal("Failed"),
"resultType": gomega.Equal(utillog.ServerErrorResultType),
"clusterIdentity": gomega.Equal(clusterIdentityServicePrincipalMetricName),
},
},
},
Expand All @@ -613,18 +620,20 @@ func TestAsyncOperationResultLog(t *testing.T) {
),
wantEntries: []map[string]types.GomegaMatcher{
{
"LOGKIND": gomega.Equal("asyncqos"),
"operationType": gomega.Equal("Failed"),
"resultType": gomega.Equal(utillog.UserErrorResultType),
"LOGKIND": gomega.Equal("asyncqos"),
"operationType": gomega.Equal("Failed"),
"resultType": gomega.Equal(utillog.UserErrorResultType),
"clusterIdentity": gomega.Equal(clusterIdentityServicePrincipalMetricName),
},
},
},
} {
t.Run(tt.name, func(t *testing.T) {
h, log := testlog.New()
doc := api.ExampleOpenShiftClusterDocument()

ocb := &openShiftClusterBackend{}
ocb.asyncOperationResultLog(log, tt.initialProvisioningState, tt.backendErr)
ocb.asyncOperationResultLog(log, doc, tt.initialProvisioningState, tt.backendErr)
err := testlog.AssertLoggingOutput(h, tt.wantEntries)
if err != nil {
t.Error(err)
Expand Down

0 comments on commit 33d7f00

Please sign in to comment.