dm03514 / bcrypt-worker

1 stars 1 forks source link

bcrypt-worker

An HTTP server to hash passwords using bcrypt.

Getting Started

Check a password

$ make ping-server
curl \
        -X POST \
        -H "Content-Type: application/json" \
        -d @tests/fixtures/password_no_match.json \
        http://localhost:8080/decrypt -v
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /decrypt HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 102
>
* upload completely sent off: 102 out of 102 bytes
< HTTP/1.1 200 OK
< Content-Type: application/json
< Date: Fri, 02 Nov 2018 23:23:36 GMT
< Content-Length: 16
<
{"Match":false}
* Connection #0 to host localhost left intact

Observability

The bcrypt worker comes with a prometheus dashboard and is accessible @localhost:3000 when using make stack.

screen shot 2018-10-30 at 8 04 45 pm

This includes a number of metrics which should allow for the operation of the worker service and actionable metrics which should help identify and alert when key SLOs (avaialbility, latency) are being violated. Ther metrics included are:

Launch a load test

In order to understand the performance of thew worker service a load test can be executed with:

$ make load-test LOAD_TEST_RATE=20
echo "POST http://localhost:8080/decrypt" | vegeta attack -body tests/fixtures/password_no_match.json -rate=20 -duration=0 | tee results.bin | vegeta report
Requests      [total, rate]            4337, 20.00
Duration      [total, attack, wait]    3m36.864626198s, 3m36.801482041s, 63.144157ms
Latencies     [mean, 50, 95, 99, max]  66.720569ms, 65.657269ms, 72.371326ms, 82.587951ms, 114.292254ms
Bytes In      [total, mean]            138320, 31.89
Bytes Out     [total, mean]            446711, 103.00
Success       [ratio]                  100.00%
Status Codes  [code:count]             200:4337
Error Set:

(the load test was used to generate the metric screenshots above)

Availability (Service Health)

Probing is being used in order to determine if the service is availble an HTTP probe is being executed at a 1 minute interval:

screen shot 2018-11-01 at 3 58 09 pm

SLO

Running Tests

$ make test-unit
go test github.com/dm03514/bcrypt-worker/cmd/worker github.com/dm03514/bcrypt-worker/decrypt -v
?       github.com/dm03514/bcrypt-worker/cmd/worker     [no test files]
=== RUN   TestBcrypter_IsMatch_NoMatch
--- PASS: TestBcrypter_IsMatch_NoMatch (0.07s)
=== RUN   TestBcrypter_IsMatch_True
--- PASS: TestBcrypter_IsMatch_True (0.14s)
=== RUN   TestPool_IsMatch_FalseNoMatch
--- PASS: TestPool_IsMatch_FalseNoMatch (0.08s)
PASS
ok      github.com/dm03514/bcrypt-worker/decrypt        (cached)

Using the JS Client

Executing Unit Tests:

bcrypt-worker/client/js$ make test-unit
./node_modules/mocha/bin/mocha

  Client
    compare()
Client.compare result:  { Match: false }
CompareResult.constructor:  { Match: false }
      ✓ should resolve a compare result when successful
Client.compare result:  { INVALID_KEY: true }
CompareResult.constructor:  { INVALID_KEY: true }
      ✓ should reject an error when CompareResult parsing is invalid
      - should reject an error when an a transport error is encountered

  2 passing (10ms)
  1 pending

Performance/Operation

Hasher Pool

0 Downtime Deploys

Spreading Workload