-
Notifications
You must be signed in to change notification settings - Fork 12
Cooperate/GitHub chunqi faultinjection #20
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
Conversation
d4d0097
to
d30208c
Compare
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.
/ptal
EnvEnableApiServerCircuitBreaker = "ENABLE_API_SERVER_BREAKER" | ||
EnvEnableRestCircuitBreaker = "ENABLE_REST_BREAKER" | ||
EnvEnableRestFaultInjection = "ENABLE_REST_Fault_Injection" |
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.
Env variables need to be capitalized.
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.
done
@@ -55,41 +57,114 @@ type HTTPFaultInjectionDelay struct { | |||
type HTTPFaultInjectionAbort struct { | |||
// HttpStatus is used to indicate the HTTP status code to | |||
// return to the caller. | |||
HttpStatus int32 `json:"httpStatus,omitempty"` | |||
HttpStatus HTTPSTATUS `json:"httpStatus,omitempty"` |
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.
Typo: In word HTTPSTATUS
HTTPSTATUS
-> int
we can get http status code from net/http/status.go.
const ( | ||
StatusOK HTTPSTATUS = 200 | ||
StatusBadRequest HTTPSTATUS = 400 | ||
StatusUnauthorized HTTPSTATUS = 401 | ||
StatusForbidden HTTPSTATUS = 403 | ||
StatusNotFound HTTPSTATUS = 404 | ||
StatusMethodNotAllowed HTTPSTATUS = 405 | ||
StatusNotAcceptable HTTPSTATUS = 406 | ||
StatusConflict HTTPSTATUS = 409 | ||
StatusUnsupportedMediaType HTTPSTATUS = 415 | ||
StatusUnprocessableEntity HTTPSTATUS = 422 | ||
StatusTooManyRequests HTTPSTATUS = 429 | ||
StatusInternalServerError HTTPSTATUS = 500 | ||
StatusServiceUnavailable HTTPSTATUS = 503 | ||
StatusGatewayTimeout HTTPSTATUS = 504 | ||
) |
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.
Unnecessary definitions.
// RestRule defines the target rest resource of the limiting policy | ||
type MultiRestRule struct { |
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.
modify the comment, plz
// LimitingSnapshot defines the snapshot of the whole faultinjection policy | ||
type FaultInjectionSnapshot struct { |
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.
modify the comment, plz
@@ -72,7 +72,7 @@ var circuitBreaker = &ctrlmeshv1alpha1.CircuitBreaker{ | |||
Spec: ctrlmeshv1alpha1.CircuitBreakerSpec{ | |||
Selector: &metav1.LabelSelector{ | |||
MatchLabels: map[string]string{ | |||
"test": "test", | |||
"test": "test2", |
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.
Why edit it?
if resp != nil && resp.Msg != nil && !resp.Msg.Success { | ||
return fmt.Errorf("fail to disable pod [%s, %s] circuit breaker config, %s", podIp, name, resp.Msg.Message) | ||
} | ||
klog.Infof("pod[ip=%s] faultinjection %s was disabled", podIp, name) |
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.
"circuit breaker config" -> faultinjection config?
pkg/proxy/faultinjection/manager.go
Outdated
realEndPointUrl, err := url.Parse(req.Header.Get("Mesh-Real-Endpoint")) | ||
logger.Info("receive proxy-host:%s, proxy-method:%s, Mesh-Real-Endpoint:%s", realEndPointUrl.Host, req.Method, req.Header.Get("Mesh-Real-Endpoint")) | ||
if err != nil || realEndPointUrl == nil { | ||
logger.Error(err, "Request Header Mesh-Real-Endpoint Parse Error") | ||
http.Error(w, fmt.Sprintf("Can not find real endpoint in header %s", err), http.StatusInternalServerError) | ||
return | ||
} | ||
// if enableRestFaultInjection { | ||
// result := pkgfi.ValidateRest(realEndPointUrl.Host, req.Method) | ||
// if result.Allowed == false { | ||
// logger.Error("ErrorTProxy: %s %s ValidateTrafficIntercept NOPASSED ,checkresult:\t%s", realEndPointUrl.Host, req.Method, result.Reason) | ||
// http.Error(w, fmt.Sprintf("Forbidden by ValidateTrafficIntercept breaker, %s, %s", result.Message, result.Reason), http.StatusForbidden) | ||
// return | ||
// } | ||
// } | ||
|
||
// ValidateRest check | ||
logger.Info("start ValidateRest checkrule %s %s", realEndPointUrl.Host, req.Method) | ||
validateresult := validator.ValidateRest(req.Header.Get("Mesh-Real-Endpoint"), req.Method) | ||
if !validateresult.Allowed { | ||
logger.Info("ErrorTProxy: %s %s ValidateRest NOPASSED ,checkresult:%t, validateresultReason:%s", req.Header.Get("Mesh-Real-Endpoint"), req.Method, validateresult.Allowed, validateresult.Reason) | ||
// http.Error(w, fmt.Sprintf("Forbidden by circuit ValidateRest breaker, %s, %s", validateresult.Message, validateresult.Reason), http.StatusForbidden) | ||
// return | ||
} | ||
logger.Info("TProxy: %s %s ValidateRest check PASSED", realEndPointUrl.Host, req.Method) | ||
|
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.
withFaultInjection
only takes effect for apiserver requests.
donot validate rest here
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.
add http proxy in main.go
var ( | ||
FaultInjectionStatusOpened FaultInjectionState = "Opened" | ||
FaultInjectionStatusClosed FaultInjectionState = "Closed" |
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.
Opend
and Closed
generally indicate the fuse state. What does this mean for FaultInjection
? I don't think FaultInjection
needs to have a snapshot state.
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.
A "Fault Injection snapshot" records whether an error code exception has been triggered; it is a snapshot of the occurrence of the exception.
9b8db36
to
33e3fbc
Compare
33e3fbc
to
9174b18
Compare
9174b18
to
3981a95
Compare
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
…ection' into cooperate/github-chunqi-faultinjection
…ection' into cooperate/github-chunqi-faultinjection
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.
/lgtm
What type of PR is this?
/kind feature
What this PR does / why we need it:
Which issue(s) this PR fixes:
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., design docs, usage docs, etc.: