1

我正在为向黎曼发送事件的应用程序编写单元测试。Riemann 启动非常缓慢,所以我决定启动一次,然后将实例重用于所有测试。因此,我需要在每个新测试开始时从先前测试产生的事件中清除索引。

我想要做的是以这样一种方式配置黎曼,即在接收到特殊事件时它将清除其索引。有一个似乎适合该任务的 API 调用:http ://riemann.io/api/riemann.index.html#var-clear 。但是我对 Clojure 不是很熟悉,我不知道如何使用它。这是我的配置的一部分:

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

但黎曼未能从这个错误开始: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

不是黎曼专家,只能猜测。第一个片段似乎是正确的,但可能在您调用该代码时索引尚未与核心关联?在这种情况下,您可以只Index为 value 实现协议,因此当value 为nil时它什么也不做。类似的东西(未测试)::indexnil

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

希望这会有所帮助。

于 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 回答