Skip to content

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

Merged
merged 21 commits into from
Jan 4, 2024

Conversation

spring-young
Copy link
Collaborator

@spring-young spring-young commented Jan 2, 2024

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.:


@spring-young spring-young force-pushed the cooperate/github-chunqi-faultinjection branch from d4d0097 to d30208c Compare January 2, 2024 07:55
Copy link
Member

@Eikykun Eikykun left a 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"
Copy link
Member

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.

Copy link
Collaborator Author

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"`
Copy link
Member

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.

Comment on lines 32 to 47
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
)
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary definitions.

Comment on lines 73 to 56
// RestRule defines the target rest resource of the limiting policy
type MultiRestRule struct {
Copy link
Member

Choose a reason for hiding this comment

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

modify the comment, plz

Comment on lines 145 to 146
// LimitingSnapshot defines the snapshot of the whole faultinjection policy
type FaultInjectionSnapshot struct {
Copy link
Member

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",
Copy link
Member

Choose a reason for hiding this comment

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

Why edit it?

Comment on lines 276 to 277
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)
Copy link
Member

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?

Comment on lines 309 to 334
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)

Copy link
Member

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

Copy link
Collaborator Author

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

Comment on lines 140 to 142
var (
FaultInjectionStatusOpened FaultInjectionState = "Opened"
FaultInjectionStatusClosed FaultInjectionState = "Closed"
Copy link
Member

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.

Copy link
Collaborator Author

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.

@spring-young spring-young force-pushed the cooperate/github-chunqi-faultinjection branch 2 times, most recently from 9b8db36 to 33e3fbc Compare January 3, 2024 03:22
@spring-young spring-young force-pushed the cooperate/github-chunqi-faultinjection branch from 33e3fbc to 9174b18 Compare January 3, 2024 03:37
@spring-young spring-young force-pushed the cooperate/github-chunqi-faultinjection branch from 9174b18 to 3981a95 Compare January 3, 2024 06:11
@Eikykun Eikykun changed the base branch from 231206-faultinject to main January 3, 2024 06:52
Copy link

github-actions bot commented Jan 3, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@Eikykun Eikykun added the enhancement New feature or request label Jan 3, 2024
@Eikykun Eikykun linked an issue Jan 3, 2024 that may be closed by this pull request
@spring-young
Copy link
Collaborator Author

I have read the CLA Document and I hereby sign the CLA

Copy link

codecov bot commented Jan 3, 2024

Codecov Report

Attention: 401 lines in your changes are missing coverage. Please review.

Comparison is base (3b5f3ce) 36.23% compared to head (128a21f) 42.86%.

Files Patch % Lines
pkg/proxy/faultinjection/manager.go 46.47% 141 Missing and 11 partials ⚠️
...ntrollers/faultinjection/faultinject_controller.go 67.12% 54 Missing and 17 partials ⚠️
...anager/controllers/faultinjection/event_handler.go 44.70% 42 Missing and 5 partials ⚠️
pkg/manager/controllers/faultinjection/cache.go 40.00% 37 Missing and 2 partials ⚠️
pkg/proxy/faultinjection/store.go 63.88% 36 Missing and 3 partials ⚠️
pkg/proxy/http/http_proxy.go 57.44% 16 Missing and 4 partials ⚠️
pkg/proxy/faultinjection/lease.go 51.72% 13 Missing and 1 partial ⚠️
pkg/proxy/grpcserver/faultinject_handler.go 0.00% 9 Missing ⚠️
...anager/controllers/circuitbreaker/event_handler.go 50.00% 4 Missing and 1 partial ⚠️
pkg/proxy/grpcserver/throttling_handler.go 66.66% 2 Missing and 1 partial ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #20      +/-   ##
==========================================
+ Coverage   36.23%   42.86%   +6.62%     
==========================================
  Files          16       26      +10     
  Lines        1904     2788     +884     
==========================================
+ Hits          690     1195     +505     
- Misses       1147     1485     +338     
- Partials       67      108      +41     
Flag Coverage Δ
unittests 42.86% <55.54%> (+6.62%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@Eikykun Eikykun left a comment

Choose a reason for hiding this comment

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

/lgtm

@Eikykun Eikykun merged commit 24cb737 into main Jan 4, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jan 4, 2024
@Eikykun Eikykun deleted the cooperate/github-chunqi-faultinjection branch January 9, 2024 04:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: FaultInjection
2 participants