首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当收到特定事件时,如何清除Riemann索引?

当收到特定事件时,如何清除Riemann索引?
EN

Stack Overflow用户
提问于 2015-10-05 21:40:50
回答 2查看 420关注 0票数 1

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

我要做的是配置Riemann,这样在接收到一个特殊事件时,它就会清除它的索引。有一个API调用似乎适合这个任务:http://riemann.io/api/riemann.index.html#var-clear。但我对Clojure并不十分熟悉,我也不知道如何使用它。下面是我配置的一部分:

代码语言:javascript
复制
(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

这一点也不起作用:

代码语言:javascript
复制
(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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-10-07 00:02:04

相反,尝试立即计算(riemann.index/clear (:index @core)),我需要一个在事件到达时将被调用的函数:

代码语言:javascript
复制
(streams
  (where (state "clear-all")
    (fn [_]
      (riemann.index/clear (:index @core)))
    (else index)))

现在一切都正常了。

票数 0
EN

Stack Overflow用户

发布于 2015-10-06 05:52:47

里曼的专家,只能猜测。第一个片段似乎是正确的,但是当您调用该代码时,索引还没有关联到内核中呢?在本例中,您只需为nil值实现nil协议,因此当:index值为nil时,它将什么也不做。类似的东西(未经测试):

代码语言:javascript
复制
(extend-protocol riemann.index/Index
  nil
  (clear [_])
  (delete [_ _])
  (delete-exactly [_ _])
  (expire [_])
  (search [_ _])
  (update [_ _])
  (lookup [_ _ _]))

希望这会有帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32958360

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档