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

Adding warning headers #19

Merged
merged 1 commit into from
Dec 29, 2022
Merged

Conversation

crobby
Copy link
Contributor

@crobby crobby commented Dec 19, 2022

Changes:

  • Adds warnings as a value of types.APIObject and types.APIObjectList
  • Adds functionality to write warning headers to responses in a k8s-like fashion

rancher/rancher#39413

Required for rancher/steve#69

@@ -156,10 +157,16 @@ func (r *APIRequest) Option(key string) string {
}

func (r *APIRequest) WriteResponse(code int, obj APIObject) {
for _, warning := range obj.Warnings {
r.Response.Header().Add("Warning", fmt.Sprintf("%d - %s", warning.Code, warning.Text))
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the same format k8s uses 👍

@@ -229,16 +236,24 @@ type APIEvent struct {
Data interface{} `json:"data,omitempty"`
}

type Warning struct {
Code int
Agent string
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see this being used here or in the steve PR, is it necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the steve side does keep a slice of these in the "WarningBuffer"

Copy link
Contributor

Choose a reason for hiding this comment

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

I see it adding it to the slice https://github.com/rancher/steve/pull/69/files#diff-82b79befb09b4c7baa9a34e0412389dc2be544a3e56086726419bbf939a9e9b9R74 but where does it actually use it? Only the Code and Text are used in the warning message string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh...your comment was specifically on "Agent"...sorry...it was early. It might not be necessary, I'll check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Upon further review, the "agent" is part of the spec for warning headers, even though it's likely to be set to "-", I think we should keep it. I will add it to what is logged just in case it ever proves to be useful.

Changes:
- Adds warnings as a value of types.APIObject and types.APIObjectList
- Adds functionality to write warning headers to responses in a k8s-like
  fashion
@crobby crobby requested a review from a team December 23, 2022 15:28
@samjustus samjustus requested review from maxsokolovsky and removed request for KevinJoiner December 27, 2022 21:00
@@ -156,10 +157,16 @@ func (r *APIRequest) Option(key string) string {
}

func (r *APIRequest) WriteResponse(code int, obj APIObject) {
for _, warning := range obj.Warnings {
r.Response.Header().Add("Warning", fmt.Sprintf("%d %s %s", warning.Code, warning.Agent, warning.Text))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: looks like the K8s format uses a dash after the code. For example:
Warning: 299 - "policy/v1beta1 PodSecurityPolicy is deprecated in v1.21+, unavailable in v1.25+"
But I am not sure how the agent's string comes into play here.

Copy link
Contributor

Choose a reason for hiding this comment

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

See #19 (comment) the agent may itself just be the string "-"

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.

5 participants