Skip to content

Commit

Permalink
draft add info identifiers in the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ying-jeanne committed Jun 14, 2024
1 parent 307f915 commit d719da4
Show file tree
Hide file tree
Showing 11 changed files with 465 additions and 236 deletions.
2 changes: 1 addition & 1 deletion model/textparse/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ In the rare case that you need to update the textparse lexers, edit promlex.l or
`golex -o=promlex.l.go promlex.l`

Note that you need golex installed:
`go get -u modernc.org/golex`
`go install -u modernc.org/golex@latest`
4 changes: 4 additions & 0 deletions model/textparse/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ type Parser interface {
// The returned byte slices become invalid after the next call to Next.
Unit() ([]byte, []byte)

// Identifiers returns the identifiers for info metrics
Identifiers() []string

// Comment returns the text of the current comment.
// Must only be called after Next returned a comment entry.
// The returned byte slice becomes invalid after the next call to Next.
Expand Down Expand Up @@ -110,4 +113,5 @@ const (
EntryComment Entry = 3
EntryUnit Entry = 4
EntryHistogram Entry = 5 // A series with a native histogram as a value.
EntryIdent Entry = 6
)
6 changes: 5 additions & 1 deletion model/textparse/openmetricslex.l
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ M [a-zA-Z_:]
C [^\n]
S [ ]

%x sComment sMeta1 sMeta2 sLabels sLValue sValue sTimestamp sExemplar sEValue sETimestamp
%x sComment sMeta1 sMeta2 sLabels sLValue sValue sTimestamp sExemplar sEValue sETimestamp sMeta3

%yyc c
%yyn c = l.next()
Expand All @@ -50,9 +50,13 @@ S [ ]
<sComment>TYPE{S} l.state = sMeta1; return tType
<sComment>UNIT{S} l.state = sMeta1; return tUnit
<sComment>"EOF"\n? l.state = sInit; return tEOFWord
<sComment>IDENS{S} l.state = sMeta3; return tIdens
<sMeta1>\"(\\.|[^\\"])*\" l.state = sMeta2; return tMName
<sMeta1>{M}({M}|{D})* l.state = sMeta2; return tMName
<sMeta2>{S}{C}*\n l.state = sInit; return tText
<sMeta3>{L}* return tLName
<sMeta3>, return tComma
<sMeta3>\n l.state = sInit; return tLinebreak
{M}({M}|{D})* l.state = sValue; return tMName
<sValue>\{ l.state = sLabels; return tBraceOpen
Expand Down
Loading

0 comments on commit d719da4

Please sign in to comment.