-
Notifications
You must be signed in to change notification settings - Fork 22
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 #49 from asafch/v2.0.0
V2.0.0
- Loading branch information
Showing
26 changed files
with
2,017 additions
and
1,897 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,9 +71,9 @@ jobs: | |
key: ${{ runner.os }}-maven-${{ hashFiles( 'project.clj' ) }} | ||
restore-keys: | | ||
${{ runner.os }}-maven- | ||
- name: Unit tests | ||
run: lein eftest | ||
- name: Publish Unit Test Results | ||
- name: Unit and Integration tests | ||
run: lein eftest :all | ||
- name: Publish unit and integration test results | ||
uses: EnricoMi/[email protected] | ||
if: always() | ||
with: | ||
|
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 |
---|---|---|
|
@@ -71,9 +71,9 @@ jobs: | |
key: ${{ runner.os }}-maven-${{ hashFiles( 'project.clj' ) }} | ||
restore-keys: | | ||
${{ runner.os }}-maven- | ||
- name: Unit tests | ||
run: lein eftest | ||
- name: Publish Unit Test Results | ||
- name: Unit and Integration tests | ||
run: lein eftest :all | ||
- name: Publish unit and integration test results | ||
uses: EnricoMi/[email protected] | ||
if: always() | ||
with: | ||
|
Empty file.
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 |
---|---|---|
@@ -1,44 +1,55 @@ | ||
## Advanced asynchronous hooks: | ||
Since `aerospike-clj` uses a future based model instead of a callback based model, it is convenient to compose complex asynchronous logic using [manifold](https://github.com/ztellman/manifold). | ||
Since `aerospike-clj` uses a future based model instead of a callback based model, | ||
it is convenient to compose complex asynchronous logic using [promesa](https://github.com/funcool/promesa). | ||
|
||
By implementing `ClientEvents` 2 hooks are exposed that are called for each API call: `on-success` and `on-failure`. | ||
By implementing the `ClientEvents` protocol 2 hooks are exposed that are called | ||
for each API call: `on-success` and `on-failure`. | ||
|
||
Those hooks are called with valuable information that can be used, for example to configure automatic logging, or telemtry on your client. Here is an example of a such code, that is reporting useful metrics to [statsd](https://github.com/etsy/statsd). So assuming you have some `statsd` namespace tha can connect and report a statsd server, and some `metrics` namespace that is used to properly format the metric names: | ||
Those hooks are called with valuable information that can be used, for example | ||
to configure automatic logging or metrics on your client. Here is an example of | ||
such code that is reporting useful metrics to [statsd](https://github.com/etsy/statsd). | ||
So assuming you have some `statsd` namespace tha can connect and report to a `statsd` | ||
server, and some `metrics` namespace that is used to properly format the metric names: | ||
```clojure | ||
(ns af-common-rta-aerospike.core | ||
(:require [aerospike-clj.client :as aero] | ||
(:require [aerospike-clj.protocols :as pt] | ||
[statsd.metrics :as metrics] | ||
[statsd.core :as statsd] | ||
[manifold.deferred :as d])) | ||
[promesa.core :as p])) | ||
|
||
(defrecord DBMeter [] | ||
client/ClientEvents | ||
(on-success [_ op-name op-result _index op-start-time client] | ||
(statsd/send-timing (metrics/format-statsd-metric (:cluster-name client) op-name "latency") | ||
(defrecord DBMeter [cluster-name] | ||
pt/ClientEvents | ||
(on-success [_ op-name op-result _index op-start-time] | ||
(statsd/send-timing (metrics/format-statsd-metric cluster-name op-name "latency") | ||
(micros-from op-start-time) | ||
STATSD-RATE) | ||
(statsd/inc-metric (metrics/format-statsd-metric (:cluster-name client) op-name "success")) | ||
(statsd/inc-metric (metrics/format-statsd-metric cluster-name op-name "success")) | ||
(when (= "read" op-name) | ||
(if (some? op-result) | ||
(statsd/inc-metric (metrics/format-statsd-metric (:cluster-name client) "read" "hit")) | ||
(statsd/inc-metric (metrics/format-statsd-metric (:cluster-name client) "read" "miss")))) | ||
(statsd/inc-metric (metrics/format-statsd-metric cluster-name "read" "hit")) | ||
(statsd/inc-metric (metrics/format-statsd-metric cluster-name "read" "miss")))) | ||
op-result) | ||
(on-failure [_ op-name op-ex index op-start-time client] | ||
(statsd/send-timing (metrics/format-statsd-metric (:cluster-name client) op-name "latency") | ||
(on-failure [_ op-name op-ex index op-start-time] | ||
(statsd/send-timing (metrics/format-statsd-metric cluster-name op-name "latency") | ||
(micros-from op-start-time) | ||
STATSD-RATE) | ||
(statsd/inc-metric (metrics/format-statsd-metric-fail-aerospike op-ex (:cluster-name client) op-name)) | ||
(d/error-deferred op-ex))) | ||
(p/rejected! op-ex))) | ||
``` | ||
A few notes on the above code: | ||
1. Passed arguments: | ||
* `op-name`, `op-result` and `index` are strings. They partially used for metrics generation in our case. | ||
* `client` here is the `IAerospikeClient` instace. You can use its fields here, or you can even `assoc` more keys on it when you create it, to be later used here. | ||
* `op-start-time` is `(System/nanoTime)`, converted here to microseconds and used to measure latency. | ||
2. The code is using the passed arguments to measure latency, format metrics names. You can easily do other stuff like logging etc. | ||
3. Both `on-success` and `on-failure` return the results passed in. Although this logic is the last logic that happens to the operations results (e.g. after trascoders are being run), the returned result will be what the calling code gets as a returned value. | ||
* `op-name`, `op-result` and `index` are strings. They are partially used for | ||
metrics generation in our case. | ||
* `op-start-time` is `(System/nanoTime)`, converted here to microseconds and | ||
used to measure latency. | ||
2. The code is using the passed arguments to measure latency and format metrics' | ||
names. You can easily do other stuff like logging, etc. | ||
3. Both `on-success` and `on-failure` return the results passed in. Although this | ||
logic is the last logic that happens to the operations' results (e.g. after | ||
transcoders are called), the returned result will be what the calling code gets | ||
as a returned value. | ||
|
||
Finally, hook it to your client: | ||
```clojure | ||
user=> (def c (aero/init-simple-aerospike-client ["localhost"] "test" {:client-events (->DBMeter)})) | ||
user=> (def c (aero/init-simple-aerospike-client ["localhost"] "test" {:client-events (->DBMeter "test-cluster")})) | ||
``` |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.