-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #336 from gofr-dev/release/v1.0.0
Release v1.0.0
- Loading branch information
Showing
111 changed files
with
7,075 additions
and
386 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Circuit Breaker in HTTP Communication | ||
|
||
Calls to remote resources and services can fail due to temporary issues like slow network connections or timeouts, as well as longer-lasting problems such as service unavailability. While transient faults can be mitigated using the "Retry pattern," there are cases where continual retries are futile, such as during severe service failures. | ||
|
||
In such scenarios, it's crucial for applications to recognize when an operation is unlikely to succeed and handle the failure appropriately rather than persistently retrying. Indiscriminate use of HTTP retries can even lead to unintentional denial-of-service attacks within the software itself, as multiple clients may flood a failing service with retry attempts. | ||
|
||
To prevent this, a defense mechanism like the circuit breaker pattern is essential. Unlike the "Retry pattern" which aims to eventually succeed, the circuit breaker pattern focuses on preventing futile operations. While these patterns can be used together, it's vital for the retry logic to be aware of the circuit breaker's feedback and cease retries if the circuit breaker indicates a non-transient fault. | ||
|
||
GoFr inherently provides the functionality, it can be enabled by passing circuit breaker configs as options to `AddHTTPService()` method. | ||
|
||
## Usage | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"time" | ||
|
||
"gofr.dev/pkg/gofr" | ||
"gofr.dev/pkg/gofr/service" | ||
) | ||
|
||
func main() { | ||
// Create a new application | ||
app := gofr.New() | ||
|
||
app.AddHTTPService("order", "https://order-func", | ||
&service.CircuitBreakerConfig{ | ||
// Number of consecutive failed requests after which circuit breaker will be enabled | ||
Threshold: 4, | ||
// Time interval at which circuit breaker will hit the aliveness endpoint. | ||
Interval: 1 * time.Second, | ||
}, | ||
) | ||
|
||
app.GET("/order", Get) | ||
|
||
// Run the application | ||
app.Run() | ||
} | ||
``` | ||
|
||
Circuit breaker state changes to open when number of consecutive failed requests increases the threshold. | ||
When it is in open state, GoFr makes request to the aliveness endpoint (default being - /.well-known/alive) at an equal interval of time provided in config. | ||
|
||
To override the default aliveness endpoint [refer](/docs/advanced-guide/monitoring-service-health) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Custom Spans In Tracing | ||
|
||
GoFr's built-in tracing provides valuable insights into your application's behavior. However, sometimes you might need | ||
even more granular details about specific operations within your application. This is where `custom spans` come in. | ||
|
||
## How it helps? | ||
By adding custom spans in traces to your requests, you can: | ||
|
||
- **Gain granular insights:** Custom spans allow you to track specific operations or functions within your application, | ||
providing detailed performance data. | ||
- **Identify bottlenecks:** By analyzing custom spans, you can pinpoint areas of your code that may be causing | ||
performance bottlenecks or inefficiencies. | ||
- **Improve debugging:** Custom spans enhance your ability to debug issues by providing visibility into the execution | ||
flow of your application. | ||
|
||
## Usage | ||
|
||
To add a custom trace to a request, you can use the `Trace()` method of GoFr context, which takes the name of the span as an argument | ||
and returns a trace.Span. | ||
|
||
```go | ||
func MyHandler(c context.Context) error { | ||
span := c.Trace("my-custom-span") | ||
defer span.Close() | ||
|
||
// Do some work here | ||
return nil | ||
} | ||
``` | ||
|
||
In this example, **my-custom-span** is the name of the custom span that you want to add to the request. | ||
The defer statement ensures that the span is closed even if an error occurs to ensure that the trace is properly recorded. | ||
|
||
|
||
|
This file contains 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.