-
Notifications
You must be signed in to change notification settings - Fork 7
Add PATCH Request Scenario to kperf for Evaluating Latency of Mutating API Calls #187
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
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
79b53a3
add PATCH request operation
vittoriasalim fb708ca
fix comments
vittoriasalim 7af3742
delete testing file
vittoriasalim 6bc293a
clean up
vittoriasalim 2ca1048
add error for invalid patch types
vittoriasalim dfd45b0
add comments for patch types
vittoriasalim 67a531c
cleaning up
vittoriasalim 6a954a7
cleaning up
vittoriasalim 50e5745
clean up
vittoriasalim b0c508e
move validation to load profile
vittoriasalim 889bc6f
fix lint
vittoriasalim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,11 @@ | |
|
||
package types | ||
|
||
import "fmt" | ||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// ContentType represents the format of response. | ||
type ContentType string | ||
|
@@ -87,6 +91,8 @@ | |
QuorumGet *RequestGet `json:"quorumGet,omitempty" yaml:"quorumGet,omitempty"` | ||
// Put means this is mutating request. | ||
Put *RequestPut `json:"put,omitempty" yaml:"put,omitempty"` | ||
// Patch means this is mutating request to update resource. | ||
Patch *RequestPatch `json:"patch,omitempty" yaml:"patch,omitempty"` | ||
// GetPodLog means this is to get log from target pod. | ||
GetPodLog *RequestGetPodLog `json:"getPodLog,omitempty" yaml:"getPodLog,omitempty"` | ||
} | ||
|
@@ -146,6 +152,19 @@ | |
ValueSize int `json:"valueSize" yaml:"valueSize"` | ||
} | ||
|
||
// RequestPatch defines PATCH request for target resource type. | ||
type RequestPatch struct { | ||
KubeGroupVersionResource `yaml:",inline"` | ||
// Namespace is object's namespace. | ||
Namespace string `json:"namespace" yaml:"namespace"` | ||
// Name is object's prefix name. | ||
Name string `json:"name" yaml:"name"` | ||
// PatchType is the type of patch, e.g. "json", "merge", "strategic-merge". | ||
PatchType string `json:"patchType" yaml:"patchType"` | ||
// Body is the request body, for fields to be changed. | ||
Body string `json:"body" yaml:"body"` | ||
} | ||
|
||
// RequestGetPodLog defines GetLog request for target pod. | ||
type RequestGetPodLog struct { | ||
// Namespace is pod's namespace. | ||
|
@@ -221,6 +240,8 @@ | |
return r.QuorumGet.Validate() | ||
case r.Put != nil: | ||
return r.Put.Validate() | ||
case r.Patch != nil: | ||
return r.Patch.Validate() | ||
case r.GetPodLog != nil: | ||
return r.GetPodLog.Validate() | ||
default: | ||
|
@@ -304,3 +325,38 @@ | |
} | ||
return nil | ||
} | ||
|
||
var PatchTypeMapping = map[string]string{ | ||
"json": "application/json-patch+json", // RFC 6902 JSON Patch | ||
"merge": "application/merge-patch+json", // RFC 7396 JSON Merge Patch | ||
"strategic-merge": "application/strategic-merge-patch+json", // Kubernetes Strategic Merge | ||
} | ||
|
||
// Validate validates RequestPatch type. | ||
func (r *RequestPatch) Validate() error { | ||
if err := r.KubeGroupVersionResource.Validate(); err != nil { | ||
return fmt.Errorf("kube metadata: %v", err) | ||
} | ||
if r.Name == "" { | ||
return fmt.Errorf("name is required") | ||
} | ||
if r.Body == "" { | ||
return fmt.Errorf("body is required") | ||
} | ||
|
||
// Validate patch type | ||
_, ok := PatchTypeMapping[r.PatchType] | ||
if !ok { | ||
return fmt.Errorf("unknown patch type: %s (valid types: json, merge, strategic-merge)", r.PatchType) | ||
} | ||
|
||
// Validate JSON body and trim it | ||
trimmed := strings.TrimSpace(r.Body) | ||
if !json.Valid([]byte(trimmed)) { | ||
return fmt.Errorf("invalid JSON in patch body: %q", r.Body) | ||
} | ||
|
||
Comment on lines
+347
to
+358
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed #187 (comment) #187 (comment) Move validation to kperf: idx: 0 request: unknown patch type: strategic-mergd (valid types: json, merge, strategic-merge) |
||
r.Body = trimmed // Store the trimmed body | ||
|
||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion adding function instead of exported var.
You can handle it in the following-up.