Skip to content

Commit

Permalink
Add invalid label names
Browse files Browse the repository at this point in the history
  • Loading branch information
janstenpickle committed Oct 21, 2022
1 parent c35d6e3 commit aa3f5c1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion core/src/main/scala/prometheus4cats/Label.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,21 @@ object Label {

}

object Name extends internal.Refined.StringRegexRefinement[Name] with LabelNameFromStringLiteral {
object Name extends internal.Refined[String, Name] with LabelNameFromStringLiteral {
// prevents macro compilation problems with the status label
private[prometheus4cats] val outcomeStatus = new Name("outcome_status")

private val invalidNames: Set[String] = Set("quantile", "le")

protected val regex: Pattern = "^[a-zA-Z_:][a-zA-Z0-9_:]*$".r.pattern

override protected def make(a: String): Name = new Name(a)

override protected def test(a: String): Boolean =
!invalidNames.contains(a) && regex.matcher(a).matches()

override protected def nonMatchMessage(a: String): String =
s"Label.Name must match pattern `$regex` and not be one of ${invalidNames.mkString(",")}"
}

}

0 comments on commit aa3f5c1

Please # to comment.