Skip to content

Commit

Permalink
lwcapi: update /evaluate to accept events (Netflix#1630)
Browse files Browse the repository at this point in the history
They will get passed through similar to diagnostic messages.
  • Loading branch information
brharrington authored and manolama committed May 22, 2024
1 parent f3580c8 commit 30e2b8c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.netflix.atlas.core.util.SortedTagMap
import com.netflix.atlas.eval.model.LwcDatapoint
import com.netflix.atlas.eval.model.LwcDiagnosticMessage
import com.netflix.atlas.eval.model.LwcEvent
import com.netflix.atlas.eval.util.SortedTagMapDeserializer
import com.netflix.atlas.json.JsonSupport
import com.netflix.atlas.pekko.CustomDirectives.*
Expand Down Expand Up @@ -54,6 +55,9 @@ class EvaluateApi(registry: Registry, sm: StreamSubscriptionManager)
}
evaluate(addr, id, datapoints)
}
req.events.groupBy(_.id).foreach {
case (id, events) => evaluate(addr, id, events)
}
req.messages.groupBy(_.id).foreach {
case (id, ms) => evaluate(addr, id, ms)
}
Expand Down Expand Up @@ -89,6 +93,7 @@ object EvaluateApi {
case class EvaluateRequest(
timestamp: Long,
metrics: List[Item] = Nil,
events: List[LwcEvent] = Nil,
messages: List[LwcDiagnosticMessage] = Nil
) extends JsonSupport
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
*/
package com.netflix.atlas.lwcapi

import com.fasterxml.jackson.databind.JsonNode
import org.apache.pekko.http.scaladsl.model.StatusCodes
import org.apache.pekko.http.scaladsl.testkit.RouteTestTimeout
import com.netflix.atlas.core.util.SortedTagMap
import com.netflix.atlas.eval.model.LwcDiagnosticMessage
import com.netflix.atlas.eval.model.LwcEvent
import com.netflix.atlas.json.Json
import com.netflix.atlas.lwcapi.EvaluateApi.*
import com.netflix.atlas.pekko.DiagnosticMessage
import com.netflix.atlas.pekko.testkit.MUnitRouteSuite
Expand All @@ -42,15 +45,23 @@ class EvaluateApiSuite extends MUnitRouteSuite {

test("post metrics") {
val metrics = List(Item("abc", SortedTagMap("a" -> "1"), 42.0))
val json = EvaluateRequest(1234L, metrics, Nil).toJson
val json = EvaluateRequest(1234L, metrics, Nil, Nil).toJson
Post("/lwc/api/v1/evaluate", json) ~> endpoint.routes ~> check {
assertEquals(response.status, StatusCodes.OK)
}
}

test("post events") {
val events = List(LwcEvent("abc", Json.decode[JsonNode]("42.0")))
val json = EvaluateRequest(1234L, Nil, events, Nil).toJson
Post("/lwc/api/v1/evaluate", json) ~> endpoint.routes ~> check {
assertEquals(response.status, StatusCodes.OK)
}
}

test("post diagnostic message") {
val msgs = List(LwcDiagnosticMessage("abc", DiagnosticMessage.error("bad expression")))
val json = EvaluateRequest(1234L, Nil, msgs).toJson
val json = EvaluateRequest(1234L, Nil, Nil, msgs).toJson
Post("/lwc/api/v1/evaluate", json) ~> endpoint.routes ~> check {
assertEquals(response.status, StatusCodes.OK)
}
Expand Down

0 comments on commit 30e2b8c

Please sign in to comment.