You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, supported KairosDB types are represented by classes that extend the sealed trait KairosCompatibleType, with implementations KNumber and KString. We might use a typeclass instead so users can specify their own types (for when they have custom data types).
Here's one idea:
trait KairosCompatibleTypeTypeClass[A] extends Format[A] {
/** The KairosDB name for the type */
val typeName: String
}
object KairosString extends KairosCompatibleTypeTypeClass[String] {
override val typeName: String = "string"
override def writes(o: String): JsValue = JsString(o)
override def reads(json: JsValue): JsResult[String] = json.validate[String]
}
object KairosBigDecimal extends KairosCompatibleTypeTypeClass[BigDecimal] {
override val typeName: String = "number"
override def writes(o: BigDecimal): JsValue = JsNumber(o)
override def reads(json: JsValue): JsResult[BigDecimal] = json.validate[BigDecimal]
}
case class DataPointWithTypeclassValue[A](metricName: MetricName, value: A, timestamp: Instant, tags: Seq[Tag], ttl: Option[FiniteDuration] = None) extends DataPoint
def addDataPointsWithTypeClass[A](dataPoints: Seq[DataPointWithTypeclassValue[A]])(implicit evidence: KairosCompatibleTypeTypeClass[A]): Future[Unit] = {
val body = Json.toJson(dataPoints)
wsClient
.url(uri / "api" / "v1" / "datapoints")
.applyKairosDBAuth
.post(body)
.map { res =>
res.status match {
case 204 => ()
case 400 => throw KairosDBResponseBadRequestException(errors = getErrors(res))
case 500 => throw KairosDBResponseInternalServerErrorException(errors = getErrors(res))
}
}
}
I'm not sure, but I believe that this will make it impossible to mix datapoints with values of different types (e.g. a datapoint with a number and a datapoint with a string). Perhaps using some Scala type magic?
The text was updated successfully, but these errors were encountered:
Currently, supported KairosDB types are represented by classes that extend the sealed trait
KairosCompatibleType
, with implementationsKNumber
andKString
. We might use a typeclass instead so users can specify their own types (for when they have custom data types).Here's one idea:
And then using it:
I'm not sure, but I believe that this will make it impossible to mix datapoints with values of different types (e.g. a datapoint with a number and a datapoint with a string). Perhaps using some Scala type magic?
The text was updated successfully, but these errors were encountered: