Sign inSign up

horneds/knocker

By horneds

Updated about 1 year ago

Image
0

2.0K

horneds/knocker repository overview

Knocker

The Knocker Service is a simple ready-to-deploy service to retry HTTP calls.

tests dockerhub

Let's imagine that your application is making HTTP webhook calls when something happens. And you need to be really sure that the webhooks reach their destinations. In this case you may add additional logic to your app, setup some kind of queue to retry the failed requests or let the Knocker do everything for you automatically.

The features:

  • Working as a web-service
  • Usable Interface to make HTTP calls
  • Configurable (timeouts, retry-policies)
  • Callbacks for failed requests and etc
  • Sentry Integration

Public version is available here: https://knock.horneds.com

Getting started

There is a docker container horneds/knocker available. Example run (locally):


    docker run --rm -p 0.0.0.0:8000:8000 horneds/knocker

Service will be available http://localhost:8000

Making a requests

Basically, all you need to make requests with Knocker is to change URL HOST to your Knocker Instance and put the original one into Knocker-Host header.

Let's imagine you have a Knockout Service is running behind the URL: https://knock.horneds.com and you want to make a request to https://target-server.com/webhook/?some-params=12

Request:

POST /webhook/?some-params=12 HTTP/1.1
Host: knock.horneds.com
Content-Type: application/json
Knocker-Host: target-server.com
Knocker-Timeout: 15.0
Knocker-Retries: 5

"SOME REQUEST BODY"

Response:

HTTP/1.1 200 OK
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/json
Date: Tue, 02 Jun 2020 15:10:37 GMT
Transfer-Encoding: chunked

{
    "config": {
        "backoff_factor": 0.5,
        "callback": null,
        "retries": 5,
        "timeout": 15.0,
        "id": "4498279872/4494502784",
    },
    "status": true
}

Knocker will attempt to make a POST request to https://target-server.com/webhook/?some-params=12 with the given request's body. It will retry the request 5 times after fails (response status 4**, 5**)

Configuration per a request

Requests parameters are passed through HTTP headers:

HeaderDescription
KNOCKER-HOSTHTTP Host to make a call (required)
KNOCKER-SCHEMEHTTP Scheme to make a call (optional)
KNOCKER-TIMEOUTTimeout in seconds (float, optional)
KNOCKER-RETRIESNumber of attempts to make HTTP call if previous one was failed (optional)
KNOCKER-BACKOFF-FACTORA backoff factor in seconds to apply between attempts after the second try
KNOCKER-CALLBACKAn URL to make a callback call if all attemps are failed (optional)
KNOCKER-IDCustom ID for the request (optional, by default Knocker creates one by itself)

All other headers which begin from knocker- prefix won't be sent to a target host but will be sent to a callback.

Callbacks

If all Knocker's attempts to make a given request were failed and callback url was given then Knocker will make a request to the given callback URL with params:

POST /your-callback-url
Host: origin-server.com
Content-Type: application/json

{
    "config": {
        "id": "ID", // Request ID
        // ... Request Config
    },
    "method": "GET", // Request Method
    "url": "https://target-server.com/webhook/?some-params=12 HTTP/1.1", // The URL is failed
    "status_code": 403, // Latest failed status code
}

Global Configuration

Knocker Service setups with the ENVIRONMENT variables:

Variable NameDescription (default value)
SCHEMEDefault scheme to make HTTP calls (https)
MAX_REDIRECTSMax number of allowed redirects per a call (10)
STATUS_URLA path to return Knocker Status (/knocker/status)
HOSTS_ONLYA list with hosts names, if defined only the hosts would be allowed ([])
TIMEOUTDefault timeout in seconds (10.0)
TIMEOUT_MAXMaximum allowed timeout in seconds (60.0)
RETRIESDefault number of attempts to make HTTP call (2)
RETRIES_MAXMaximum allowed number of retries (10)
RETRIES_BACKOFF_FACTORA backoff factor in seconds to apply between attempts after the second try (0.5)
RETRIES_BACKOFF_FACTOR_MAXMaximum backoff time (600)
LOG_FILE-
LOG_LEVELINFO
LOG_FORMAT%(asctime)s %(levelname)-8s %(message)s
SENTRY_DSNSet to Sentry DSN to capture any exceptions ('')
SENTRY_FAILED_REQUESTSCapture any failed requests into Sentry (false)

Bug tracker

If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/knocker/issues

Contributing

Development of The Knocker happens at: https://github.com/klen/knocker

Contributors

License

Licensed under a MIT license (See LICENSE)

Tag summary

Content type

Image

Digest

sha256:77423ac11

Size

470.4 MB

Last updated

about 1 year ago

docker pull horneds/knocker