Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce the amount of package names in the logs #3630

Merged
merged 5 commits into from
Jun 16, 2024
Merged
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
82 changes: 41 additions & 41 deletions pkg/cluster/adminupdate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,60 +33,60 @@ func TestAdminUpdateSteps(t *testing.T) {
}

zerothSteps := []string{
"[Action initializeKubernetesClients-fm]",
"[Action ensureBillingRecord-fm]",
"[Action ensureDefaults-fm]",
"[AuthorizationRetryingAction fixupClusterSPObjectID-fm]",
"[Action fixInfraID-fm]",
"[Action initializeKubernetesClients]",
"[Action ensureBillingRecord]",
"[Action ensureDefaults]",
"[AuthorizationRetryingAction fixupClusterSPObjectID]",
"[Action fixInfraID]",
}

generalFixesSteps := []string{
"[Action ensureResourceGroup-fm]",
"[Action createOrUpdateDenyAssignment-fm]",
"[Action ensureServiceEndpoints-fm]",
"[Action populateRegistryStorageAccountName-fm]",
"[Action migrateStorageAccounts-fm]",
"[Action fixSSH-fm]",
"[Action startVMs-fm]",
"[Condition apiServersReady-fm, timeout 30m0s]",
"[Action fixSREKubeconfig-fm]",
"[Action fixUserAdminKubeconfig-fm]",
"[Action createOrUpdateRouterIPFromCluster-fm]",
"[Action ensureGatewayUpgrade-fm]",
"[Action rotateACRTokenPassword-fm]",
"[Action populateRegistryStorageAccountName-fm]",
"[Action ensureMTUSize-fm]",
"[Action ensureResourceGroup]",
"[Action createOrUpdateDenyAssignment]",
"[Action ensureServiceEndpoints]",
"[Action populateRegistryStorageAccountName]",
"[Action migrateStorageAccounts]",
"[Action fixSSH]",
"[Action startVMs]",
"[Condition apiServersReady, timeout 30m0s]",
"[Action fixSREKubeconfig]",
"[Action fixUserAdminKubeconfig]",
"[Action createOrUpdateRouterIPFromCluster]",
"[Action ensureGatewayUpgrade]",
"[Action rotateACRTokenPassword]",
"[Action populateRegistryStorageAccountName]",
"[Action ensureMTUSize]",
}

certificateRenewalSteps := []string{
"[Action startVMs-fm]",
"[Condition apiServersReady-fm, timeout 30m0s]",
"[Action populateDatabaseIntIP-fm]",
"[Action fixMCSCert-fm]",
"[Action fixMCSUserData-fm]",
"[Action configureAPIServerCertificate-fm]",
"[Action configureIngressCertificate-fm]",
"[Action initializeOperatorDeployer-fm]",
"[Action renewMDSDCertificate-fm]",
"[Action startVMs]",
"[Condition apiServersReady, timeout 30m0s]",
"[Action populateDatabaseIntIP]",
"[Action fixMCSCert]",
"[Action fixMCSUserData]",
"[Action configureAPIServerCertificate]",
"[Action configureIngressCertificate]",
"[Action initializeOperatorDeployer]",
"[Action renewMDSDCertificate]",
}

operatorUpdateSteps := []string{
"[Action startVMs-fm]",
"[Condition apiServersReady-fm, timeout 30m0s]",
"[Action initializeOperatorDeployer-fm]",
"[Action ensureAROOperator-fm]",
"[Condition aroDeploymentReady-fm, timeout 20m0s]",
"[Condition ensureAROOperatorRunningDesiredVersion-fm, timeout 5m0s]",
"[Action startVMs]",
"[Condition apiServersReady, timeout 30m0s]",
"[Action initializeOperatorDeployer]",
"[Action ensureAROOperator]",
"[Condition aroDeploymentReady, timeout 20m0s]",
"[Condition ensureAROOperatorRunningDesiredVersion, timeout 5m0s]",
}

hiveSteps := []string{
"[Action hiveCreateNamespace-fm]",
"[Action hiveEnsureResources-fm]",
"[Condition hiveClusterDeploymentReady-fm, timeout 5m0s]",
"[Action hiveResetCorrelationData-fm]",
"[Action hiveCreateNamespace]",
"[Action hiveEnsureResources]",
"[Condition hiveClusterDeploymentReady, timeout 5m0s]",
"[Action hiveResetCorrelationData]",
}

updateProvisionedBySteps := []string{"[Action updateProvisionedBy-fm]"}
updateProvisionedBySteps := []string{"[Action updateProvisionedBy]"}

for _, tt := range []struct {
name string
Expand Down Expand Up @@ -215,7 +215,7 @@ func TestAdminUpdateSteps(t *testing.T) {
var stepsToRun []string
for _, s := range toRun {
// make it a little nicer when defining the steps that should run, since they're all methods
o := strings.Replace(s.String(), "github.com/Azure/ARO-RP/pkg/cluster.(*manager).", "", -1)
o := strings.Replace(s.String(), "pkg/cluster.(*manager).", "", -1)
stepsToRun = append(stepsToRun, o)
}

Expand Down
22 changes: 11 additions & 11 deletions pkg/cluster/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,27 @@ func TestStepRunnerWithInstaller(t *testing.T) {
wantEntries: []map[string]types.GomegaMatcher{
{
"level": gomega.Equal(logrus.InfoLevel),
"msg": gomega.Equal(`running step [Action github.com/Azure/ARO-RP/pkg/cluster.failingFunc]`),
"msg": gomega.Equal(`running step [Action pkg/cluster.failingFunc]`),
},
{
"level": gomega.Equal(logrus.ErrorLevel),
"msg": gomega.Equal("step [Action github.com/Azure/ARO-RP/pkg/cluster.failingFunc] encountered error: oh no!"),
"msg": gomega.Equal("step [Action pkg/cluster.failingFunc] encountered error: oh no!"),
},
{
"level": gomega.Equal(logrus.InfoLevel),
"msg": gomega.MatchRegexp(`(?s)github.com/Azure/ARO-RP/pkg/cluster.\(\*manager\).logClusterVersion\-fm:.*"name": "version"`),
"msg": gomega.MatchRegexp(`(?s)pkg/cluster.\(\*manager\).logClusterVersion:.*"name": "version"`),
},
{
"level": gomega.Equal(logrus.InfoLevel),
"msg": gomega.MatchRegexp(`(?s)github.com/Azure/ARO-RP/pkg/cluster.\(\*manager\).logNodes\-fm:.*"name": "node"`),
"msg": gomega.MatchRegexp(`(?s)pkg/cluster.\(\*manager\).logNodes:.*"name": "node"`),
},
{
"level": gomega.Equal(logrus.InfoLevel),
"msg": gomega.MatchRegexp(`(?s)github.com/Azure/ARO-RP/pkg/cluster.\(\*manager\).logClusterOperators\-fm:.*"name": "operator"`),
"msg": gomega.MatchRegexp(`(?s)pkg/cluster.\(\*manager\).logClusterOperators:.*"name": "operator"`),
},
{
"level": gomega.Equal(logrus.InfoLevel),
"msg": gomega.MatchRegexp(`(?s)github.com/Azure/ARO-RP/pkg/cluster.\(\*manager\).logIngressControllers\-fm:.*"name": "ingress-controller"`),
"msg": gomega.MatchRegexp(`(?s)pkg/cluster.\(\*manager\).logIngressControllers:.*"name": "ingress-controller"`),
},
},
kubernetescli: fake.NewSimpleClientset(node),
Expand All @@ -137,27 +137,27 @@ func TestStepRunnerWithInstaller(t *testing.T) {
wantEntries: []map[string]types.GomegaMatcher{
{
"level": gomega.Equal(logrus.InfoLevel),
"msg": gomega.Equal(`running step [Action github.com/Azure/ARO-RP/pkg/cluster.failingFunc]`),
"msg": gomega.Equal(`running step [Action pkg/cluster.failingFunc]`),
},
{
"level": gomega.Equal(logrus.ErrorLevel),
"msg": gomega.Equal("step [Action github.com/Azure/ARO-RP/pkg/cluster.failingFunc] encountered error: oh no!"),
"msg": gomega.Equal("step [Action pkg/cluster.failingFunc] encountered error: oh no!"),
},
{
"level": gomega.Equal(logrus.ErrorLevel),
"msg": gomega.Equal(`clusterversions.config.openshift.io "version" not found`),
},
{
"level": gomega.Equal(logrus.InfoLevel),
"msg": gomega.Equal(`github.com/Azure/ARO-RP/pkg/cluster.(*manager).logNodes-fm: null`),
"msg": gomega.Equal(`pkg/cluster.(*manager).logNodes: null`),
},
{
"level": gomega.Equal(logrus.InfoLevel),
"msg": gomega.Equal(`github.com/Azure/ARO-RP/pkg/cluster.(*manager).logClusterOperators-fm: null`),
"msg": gomega.Equal(`pkg/cluster.(*manager).logClusterOperators: null`),
},
{
"level": gomega.Equal(logrus.InfoLevel),
"msg": gomega.Equal(`github.com/Azure/ARO-RP/pkg/cluster.(*manager).logIngressControllers-fm: null`),
"msg": gomega.Equal(`pkg/cluster.(*manager).logIngressControllers: null`),
},
},
kubernetescli: fake.NewSimpleClientset(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/steps/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (c conditionStep) run(ctx context.Context, log *logrus.Entry) error {
// returns enriched error messages mentioned in timeoutConditionErrors
func enrichConditionTimeoutError(f conditionFunction, originalErr error) error {
funcNameParts := strings.Split(FriendlyName(f), ".")
funcName := strings.TrimSuffix(funcNameParts[len(funcNameParts)-1], "-fm")
funcName := funcNameParts[len(funcNameParts)-1]

message, exists := timeoutConditionErrors[funcName]
if !exists {
Expand Down
55 changes: 33 additions & 22 deletions pkg/util/steps/condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,32 @@ import (
"testing"
)

type teststruct struct{}
hawkowl marked this conversation as resolved.
Show resolved Hide resolved

// functionnames that will be used in the conditionFunction below
// All the keys of map timeoutConditionErrors
func attachNSGs(context.Context) (bool, error) { return false, nil }
func apiServersReady(context.Context) (bool, error) { return false, nil }
func minimumWorkerNodesReady(context.Context) (bool, error) { return false, nil }
func operatorConsoleExists(context.Context) (bool, error) { return false, nil }
func operatorConsoleReady(context.Context) (bool, error) { return false, nil }
func clusterVersionReady(context.Context) (bool, error) { return false, nil }
func ingressControllerReady(context.Context) (bool, error) { return false, nil }
func aroDeploymentReady(context.Context) (bool, error) { return false, nil }
func ensureAROOperatorRunningDesiredVersion(context.Context) (bool, error) { return false, nil }
func hiveClusterDeploymentReady(context.Context) (bool, error) { return false, nil }
func hiveClusterInstallationComplete(context.Context) (bool, error) { return false, nil }
func (n *teststruct) attachNSGs(context.Context) (bool, error) { return false, nil }
func (n *teststruct) apiServersReady(context.Context) (bool, error) { return false, nil }
func (n *teststruct) minimumWorkerNodesReady(context.Context) (bool, error) { return false, nil }
func (n *teststruct) operatorConsoleExists(context.Context) (bool, error) { return false, nil }
func (n *teststruct) operatorConsoleReady(context.Context) (bool, error) { return false, nil }
func (n *teststruct) clusterVersionReady(context.Context) (bool, error) { return false, nil }
func (n *teststruct) ingressControllerReady(context.Context) (bool, error) { return false, nil }
func (n *teststruct) aroDeploymentReady(context.Context) (bool, error) { return false, nil }
func (n *teststruct) ensureAROOperatorRunningDesiredVersion(context.Context) (bool, error) {
return false, nil
}
func (n *teststruct) hiveClusterDeploymentReady(context.Context) (bool, error) { return false, nil }
func (n *teststruct) hiveClusterInstallationComplete(context.Context) (bool, error) {
return false, nil
}

func TestEnrichConditionTimeoutError(t *testing.T) {
// When stringifying a method on a struct, golang adds -fm -- this is not
// useful to us, so using a struct instance here will verify that it is not
// present when matching the timeout error strings
s := &teststruct{}

for _, tt := range []struct {
desc string
function conditionFunction
Expand All @@ -41,57 +52,57 @@ func TestEnrichConditionTimeoutError(t *testing.T) {
},
{
desc: "test conditionfail for func - attachNSGs",
function: attachNSGs,
function: s.attachNSGs,
wantErr: "500: DeploymentFailed: : Failed to attach the ARO NSG to the cluster subnets. Please retry, and if the issue persists, raise an Azure support ticket",
},
{
desc: "test conditionfail for func - apiServersReady",
function: apiServersReady,
function: s.apiServersReady,
wantErr: "500: DeploymentFailed: : Kube API has not initialised successfully and is unavailable. Please retry, and if the issue persists, raise an Azure support ticket",
},
{
desc: "test conditionfail for func - minimumWorkerNodesReady",
function: minimumWorkerNodesReady,
function: s.minimumWorkerNodesReady,
wantErr: "500: DeploymentFailed: : Minimum number of worker nodes have not been successfully created. Please retry, and if the issue persists, raise an Azure support ticket",
},
{
desc: "test conditionfail for func - operatorConsoleExists",
function: operatorConsoleExists,
function: s.operatorConsoleExists,
wantErr: "500: DeploymentFailed: : Console Cluster Operator has failed to initialize successfully. Please retry, and if the issue persists, raise an Azure support ticket",
},
{
desc: "test conditionfail for func - operatorConsoleReady",
function: operatorConsoleReady,
function: s.operatorConsoleReady,
wantErr: "500: DeploymentFailed: : Console Cluster Operator has not started successfully. Please retry, and if the issue persists, raise an Azure support ticket",
},
{
desc: "test conditionfail for func - clusterVersionReady",
function: clusterVersionReady,
function: s.clusterVersionReady,
wantErr: "500: DeploymentFailed: : Cluster Verion is not reporting status as ready. Please retry, and if the issue persists, raise an Azure support ticket",
},
{
desc: "test conditionfail for func - clusterVersionReady",
function: ingressControllerReady,
function: s.ingressControllerReady,
wantErr: "500: DeploymentFailed: : Ingress Cluster Operator has not started successfully. Please retry, and if the issue persists, raise an Azure support ticket",
},
{
desc: "test conditionfail for func - aroDeploymentReady",
function: aroDeploymentReady,
function: s.aroDeploymentReady,
wantErr: "500: DeploymentFailed: : ARO Cluster Operator has failed to initialize successfully. Please retry, and if the issue persists, raise an Azure support ticket",
},
{
desc: "test conditionfail for func - ensureAROOperatorRunningDesiredVersion",
function: ensureAROOperatorRunningDesiredVersion,
function: s.ensureAROOperatorRunningDesiredVersion,
wantErr: "500: DeploymentFailed: : ARO Cluster Operator is not running desired version. Please retry, and if the issue persists, raise an Azure support ticket",
},
{
desc: "test conditionfail for func - hiveClusterDeploymentReady",
function: hiveClusterDeploymentReady,
function: s.hiveClusterDeploymentReady,
wantErr: "500: DeploymentFailed: : Timed out waiting for the condition to be ready. Please retry, and if the issue persists, raise an Azure support ticket",
},
{
desc: "test conditionfail for func - hiveClusterInstallationComplete",
function: hiveClusterInstallationComplete,
function: s.hiveClusterInstallationComplete,
wantErr: "500: DeploymentFailed: : Timed out waiting for the condition to complete. Please retry, and if the issue persists, raise an Azure support ticket",
},
} {
Expand Down
7 changes: 5 additions & 2 deletions pkg/util/steps/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ import (
msgraph_errors "github.com/Azure/ARO-RP/pkg/util/graph/graphsdk/models/odataerrors"
)

// FriendlyName returns a "friendly" stringified name of the given func.
// FriendlyName returns a "friendly" stringified name of the given func. This
// consists of removing the ARO base package name (so it produces pkg/foobar
// instead of github.com/Azure/ARO-RP/pkg/foobar) and removing the -fm suffix
// from Golang struct methods.
func FriendlyName(f interface{}) string {
return runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
return strings.TrimPrefix(strings.TrimSuffix(runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name(), "-fm"), "github.com/Azure/ARO-RP/")
}

func shortName(fullName string) string {
Expand Down
Loading
Loading