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

Add information to header #3992

Merged
merged 1 commit into from
Oct 3, 2024
Merged

Add information to header #3992

merged 1 commit into from
Oct 3, 2024

Conversation

benjaminjb
Copy link
Contributor

Checklist:

  • Have you added an explanation of what your changes do and why you'd like them to be included?
  • Have you updated or added documentation for the change, as applicable?
  • Have you tested your changes on all related environments with successful results, as applicable?
    • Have you added automated tests?

Type of Changes:

  • New feature
  • Bug fix
  • Documentation
  • Testing enhancement
  • Other

What is the current behavior (link to any open issues here)?

What is the new behavior (if this is a feature change)?

  • Breaking change (fix or feature that would cause existing functionality to change)

Other Information:
Issues: [PGO-1610, PGO-1616, PGO-1618]

@benjaminjb benjaminjb requested review from cbandy, crunchyandrew and dsessler7 and removed request for crunchyandrew September 13, 2024 19:27
internal/registration/runner_test.go Outdated Show resolved Hide resolved
internal/upgradecheck/header_test.go Show resolved Hide resolved
internal/upgradecheck/header_test.go Outdated Show resolved Hide resolved
internal/upgradecheck/helpers_test.go Outdated Show resolved Hide resolved
internal/upgradecheck/http_test.go Show resolved Hide resolved
Copy link
Contributor

@dsessler7 dsessler7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines 110 to 111
saveEnv(t, "PGO_FEATURE_GATES")
os.Setenv("PGO_FEATURE_GATES", "Tablespace=true")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 It looks like ctx is wired through from CheckForUpgradesScheduler.Start. If so,1 this test can use the feature package like so:

Suggested change
saveEnv(t, "PGO_FEATURE_GATES")
os.Setenv("PGO_FEATURE_GATES", "Tablespace=true")
gate := feature.NewGate()
assert.NilError(t, gate.SetFromMap(map[string]bool{
feature.TablespaceVolumes: true,
}))
ctx = feature.NewContext(ctx, gate)

Footnotes

  1. main.go initializes that base/root context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated


// saveEnv preserves environment variables so that any modifications needed for
// the tests can be undone once completed.
func saveEnv(t testing.TB, key string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 Use T.Setenv instead.

Copy link
Contributor Author

@benjaminjb benjaminjb Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulled that out of all the tests.

(There's no t.Unsetenv, but someone suggested using t.Setenv to save the env, and then calling os.Unsetenv, so I tried that where applicable)

Comment on lines 55 to 56
saveEnv(t, "PGO_FEATURE_GATES")
os.Setenv("PGO_FEATURE_GATES", "Tablespace=true")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ I can't tell; is there a ctx around here? If so, use that instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

internal/upgradecheck/http.go Show resolved Hide resolved
@@ -86,7 +87,7 @@ func (r *Runner) CheckToken() error {
r.token.Lock()
defer r.token.Unlock()

_, errToken := jwt.ParseWithClaims(string(data), &r.token, key,
token, errToken := jwt.ParseWithClaims(string(data), &r.token, key,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌱 Passing &r.token here doesn't seem right according to the docs, but handling custom claims through an interface... 🤔 🤔

📝 🦆 🤔 IIUC, the other package needs only a plaintext opaque blob of "token."

Comment on lines 38 to 48
BridgeClustersTotal int `json:"bridge_clusters_total"`
DeploymentID string `json:"deployment_id"`
FeatureGatesEnabled string `json:"feature_gates_enabled"`
IsOpenShift bool `json:"is_open_shift"`
KubernetesEnv string `json:"kubernetes_env"`
PGOClustersTotal int `json:"pgo_clusters_total"`
PGOVersion string `json:"pgo_version"`
RegistrationToken string `json:"registration_token"`
PGOInstaller string `json:"pgo_installer"`
PGOInstallerOrigin string `json:"pgo_installer_origin"`
BuildSource string `json:"build_source"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ We should probably alphabetize these struct fields.

Comment on lines 57 to 67
BridgeClustersTotal: getBridgeClusters(ctx, crClient),
FeatureGatesEnabled: feature.ShowGates(ctx),
IsOpenShift: isOpenShift,
DeploymentID: ensureDeploymentID(ctx, crClient),
KubernetesEnv: getServerVersion(ctx, cfg),
PGOClustersTotal: getManagedClusters(ctx, crClient),
PGOVersion: pgoVersion,
RegistrationToken: registrationToken,
PGOInstaller: os.Getenv("PGO_INSTALLER"),
PGOInstallerOrigin: os.Getenv("PGO_INSTALLER_ORIGIN"),
BuildSource: os.Getenv("BUILD_SOURCE"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ We should probably alphabetize these struct fields.

Comment on lines 129 to 131
OpenShift bool
Refresh time.Duration
URL, Version string
RegistrationToken string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ We should probably alphabetize these.

Comment on lines 153 to 159
Client: m.GetClient(),
Config: m.GetConfig(),
OpenShift: openshift,
Refresh: 24 * time.Hour,
URL: url,
Version: version,
RegistrationToken: token,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ We should probably alphabetize these.

@@ -121,3 +121,12 @@ func Enabled(ctx context.Context, f Feature) bool {
func NewContext(ctx context.Context, gate Gate) context.Context {
return context.WithValue(ctx, contextKey{}, gate)
}

func ShowGates(ctx context.Context) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ Since this is a public function, I'd like a comment.

* Crunchy Bridge clusters managed
* Features gates enabled
* Registration token
* Build metadata

Issues: [PGO-1610, PGO-1616, PGO-1618]
@benjaminjb benjaminjb merged commit 6707a99 into master Oct 3, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants