1

I am facing one scenario. Let assume I have 3 events A, B and C which I am passing to Riemann.

Event A have following fields :ExamNo 3890 :ExamResult Pass :Rank 8
Event B have following fields :ExamNo 3890 :ExamResult Pass :Rank 5
Event C have following fields :ExamNo 3890 :ExamResult Fail :Rank 0

I need to compare the events based on ExamNo and whenver there is a change in ExamResult I need to add a new fields to event {:Eligible, :Grade}. I wrote the code to compare the events but the new field was not getting added to the event.

(let [examindex (default :ttl 300 (update-index (index)))]
  (streams
    prn
    examindex))

(streams
  (where (service "Result")
    (smap
          (fn [events]
        (by[:ExamNo]
        (changed :ExamResult))
        (event
            {    :Eligible :Eligible-Status
                 :Grade     :GradeValue
            }
         )))))

Since I am newbie to Riemann . I couldn't figure out the issue.

4

1 回答 1

1

我从未使用过 Riemann,但由于您想修改现有事件,您可能应该使用with,正如这里所解释的那样,而不是event. 顺便说一句,为了清楚起见,事件是不可变的,因此您实际上是在基于旧值创建新值。

您应该尝试缩进您的代码:请注意该(event ...)表单未包含在 下(changed ...),尽管它可能应该。

测试

我在配置文件中只使用了这个streams声明:

(streams
 (where (service "Result")
    (by :ExamNo
      (changed :ExamResult
        (with {:Eligible :Eligible-Status
               :Grade    :GradeValue  }
          prn)))))))

我删除smap并添加了一个prn声明。为了测试这一点,我连接到一个nREPL客户端并从那里触发事件。首先,让我们定义一个 TCP 客户端。

(def tcp-client (riemann.client/tcp-client))

然后,发送第一个事件,没有:ExamResult值:

(riemann.client/send-event tcp-client
  (riemann.common/event {:service "Result" :ExamNo "4"}))

服务器不打印任何内容。然后,我为相同的结果发送一个新事件ExamNo

(riemann.client/send-event tcp-client
  (riemann.common/event {:service "Result" :ExamNo "4" :ExamResult "result"}))

由于自上次活动以来考试编号“4”的结果发生了变化,我们建立了一个新活动。正在运行的 Riemann 服务器在其标准输出中输出以下内容:

#riemann.codec.Event{:host "localhost", :service "Result", :state nil, 
:description nil, :metric nil, :tags nil, :time 1437035833,
:ttl nil, :Grade :GradeValue, :Eligible :Eligible-Status, 
:ExamNo "4", :ExamResult "x"}

重新注入

如果prn我使用reinject, 而不是 , 并且如果我恢复先前省略的行:

(let [examindex (default :ttl 300 (update-index (index)))]
  (streams
    prn
    examindex))

...然后显示所有事件,特别是重新注入的新事件。这种行为可能是您最初期望的行为。

于 2015-07-15T13:26:47.417 回答