1

Riemann にイベントを送信するアプリケーションの単体テストを作成しています。Riemann の起動は非常に遅いため、一度起動して、すべてのテストでインスタンスを再利用することにしました。したがって、新しい各テストの開始時に、以前のテストによって生成されたイベントからインデックスを消去する必要があります。

私がやろうとしているのは、特別なイベントを受け取ったときにインデックスをクリアするように Riemann を構成することです。このタスクに適していると思われる API 呼び出しがあります: http://riemann.io/api/riemann.index.html#var-clear。しかし、私は Clojure にあまり詳しくなく、使い方がわかりません。これが私の設定の一部です:

(streams
  index
  (where (state "clear-all")
    (riemann.index/clear (:index @core))))

しかし、Riemann は次のエラーで開始できません。No implementation of method: :clear of protocol: #'riemann.index/Index found for class: nil

これ(:index @core)は に評価されるようですnil

これも機能しません:

(streams
  index
  (where (state "clear-all")
    (riemann.index/clear index)))

エラーは次のとおりです。No implementation of method: :clear of protocol: #'riemann.index/Index found for class: riemann.streams$default$stream__9829

4

2 に答える 2

1

Not an expert in riemann, can only guess. First snippet seems to be correct, but probably by the time you call that code the index hasn't been associated in a core yet? In this case you could just implement Index protocol for nil value so it will do nothing when :index value is nil. Something like that (not tested):

(extend-protocol riemann.index/Index
  nil
  (clear [_])
  (delete [_ _])
  (delete-exactly [_ _])
  (expire [_])
  (search [_ _])
  (update [_ _])
  (lookup [_ _ _]))

hope that would be helpful.

于 2015-10-06T05:52:47.040 に答える
0

すぐに評価しようとする代わり(riemann.index/clear (:index @core))に、イベントが到着したときに呼び出される関数が必要です。

(streams
  (where (state "clear-all")
    (fn [_]
      (riemann.index/clear (:index @core)))
    (else index)))

これですべてが機能します。

于 2015-10-07T00:02:04.843 に答える