Skip to content

Commit

Permalink
docs: add loadshedding middleware to what's new document
Browse files Browse the repository at this point in the history
  • Loading branch information
ErfanMomeniii authored and Erfan Momeni committed Jan 2, 2025
1 parent 5be40f1 commit 6287ea1
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions docs/whats_new.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Here's a quick overview of the changes in Fiber `v3`:
- [Filesystem](#filesystem)
- [Monitor](#monitor)
- [Healthcheck](#healthcheck)
- [Load shedding](#loadshedding)

Check failure on line 34 in docs/whats_new.md

View workflow job for this annotation

GitHub Actions / markdownlint

Link fragments should be valid

docs/whats_new.md:34:5 MD051/link-fragments Link fragments should be valid [Context: "[Load shedding](#loadshedding)"] https://github.com/DavidAnson/markdownlint/blob/v0.37.2/doc/md051.md
- [📋 Migration guide](#-migration-guide)

## Drop for old Go versions
Expand Down Expand Up @@ -810,6 +811,15 @@ The Healthcheck middleware has been enhanced to support more than two routes, wi

Refer to the [healthcheck middleware migration guide](./middleware/healthcheck.md) or the [general migration guide](#-migration-guide) to review the changes.

### Load shedding

Check failure on line 814 in docs/whats_new.md

View workflow job for this annotation

GitHub Actions / markdownlint

Headings should be surrounded by blank lines

docs/whats_new.md:814 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "### Load shedding"] https://github.com/DavidAnson/markdownlint/blob/v0.37.2/doc/md022.md
We've added **Load Shedding Middleware**.It ensures system stability under high load by enforcing timeouts on request processing. This mechanism allows the application to shed excessive load gracefully and maintain responsiveness.

**Functionality**

Check failure on line 817 in docs/whats_new.md

View workflow job for this annotation

GitHub Actions / markdownlint

Emphasis used instead of a heading

docs/whats_new.md:817 MD036/no-emphasis-as-heading Emphasis used instead of a heading [Context: "Functionality"] https://github.com/DavidAnson/markdownlint/blob/v0.37.2/doc/md036.md
- **Timeout Enforcement**: Automatically terminates requests exceeding a specified processing time.

Check failure on line 818 in docs/whats_new.md

View workflow job for this annotation

GitHub Actions / markdownlint

Lists should be surrounded by blank lines

docs/whats_new.md:818 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- **Timeout Enforcement**: Aut..."] https://github.com/DavidAnson/markdownlint/blob/v0.37.2/doc/md032.md
- **Custom Response**: Uses a configurable load-shedding handler to define the response for shed requests.
- **Request Exclusion**: Allows certain requests to bypass load-shedding logic through an exclusion filter.

This middleware is designed to enhance server resilience and improve the user experience during periods of high traffic.
## 📋 Migration guide

Check failure on line 823 in docs/whats_new.md

View workflow job for this annotation

GitHub Actions / markdownlint

Headings should be surrounded by blank lines

docs/whats_new.md:823 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Above] [Context: "## 📋 Migration guide"] https://github.com/DavidAnson/markdownlint/blob/v0.37.2/doc/md022.md

- [🚀 App](#-app-1)
Expand Down Expand Up @@ -1361,6 +1371,34 @@ app.Get(healthcheck.DefaultStartupEndpoint, healthcheck.NewHealthChecker(healthc
app.Get("/live", healthcheck.NewHealthChecker())
```
#### Load shedding

Check failure on line 1374 in docs/whats_new.md

View workflow job for this annotation

GitHub Actions / markdownlint

Headings should be surrounded by blank lines

docs/whats_new.md:1374 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "#### Load shedding"] https://github.com/DavidAnson/markdownlint/blob/v0.37.2/doc/md022.md
This middleware uses `context.WithTimeout` to manage the lifecycle of requests. If a request exceeds the specified timeout, the custom load-shedding handler is triggered, ensuring the system remains stable under stress.
**Key Parameters**

Check failure on line 1377 in docs/whats_new.md

View workflow job for this annotation

GitHub Actions / markdownlint

Emphasis used instead of a heading

docs/whats_new.md:1377 MD036/no-emphasis-as-heading Emphasis used instead of a heading [Context: "Key Parameters"] https://github.com/DavidAnson/markdownlint/blob/v0.37.2/doc/md036.md
`timeout` (`time.Duration`): The maximum time a request is allowed to process. Requests exceeding this time are terminated.
`loadSheddingHandler` (`fiber.Handler`): A custom handler that executes when a request exceeds the timeout. Typically used to return a `503 Service Unavailable` response or a custom message.
`exclude` (`func(fiber.Ctx) bool`): A filter function to exclude specific requests from being subjected to the load-shedding logic (optional).
**Usage Example**

Check failure on line 1385 in docs/whats_new.md

View workflow job for this annotation

GitHub Actions / markdownlint

Emphasis used instead of a heading

docs/whats_new.md:1385 MD036/no-emphasis-as-heading Emphasis used instead of a heading [Context: "Usage Example"] https://github.com/DavidAnson/markdownlint/blob/v0.37.2/doc/md036.md
```go
import "github.com/gofiber/fiber/v3/middleware/loadshedding
app.Use(loadshedding.New(
10*time.Second, // Timeout duration
func(c fiber.Ctx) error { // Load shedding response
return c.Status(fiber.StatusServiceUnavailable).
SendString("Service overloaded, try again later.")
},
func(c fiber.Ctx) bool { // Exclude health checks
return c.Path() == "/health"
},
))
```
#### Monitor
Since v3 the Monitor middleware has been moved to the [Contrib package](https://github.com/gofiber/contrib/tree/main/monitor)
Expand Down

0 comments on commit 6287ea1

Please sign in to comment.