Skip to content

Commit

Permalink
Little proffing of convArtiToPromNumber. (#151)
Browse files Browse the repository at this point in the history
A Peiman wrote in #150 (review)

Co-authored-by: Peiman Jafari <[email protected]>
  • Loading branch information
KacperPerschke and peimanja authored Dec 6, 2024
1 parent bdc763d commit 149f078
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions collector/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func convArtiToPromBool(b bool) float64 {
}

const (
pattNumber = `^(?P<number>[[:digit:]]{1,4}(?:,[[:digit:]]{3})*(?:\.[[:digit:]]{1,2})?) ?(?P<multiplier>%|bytes|[KMGT]B)?$`
pattNumber = `^(?P<number>[[:digit:]]{1,3}(?:[[:digit:]]|(?:,[[:digit:]]{3})*(?:\.[[:digit:]]{1,2}))?) ?(?P<multiplier>%|bytes|[KMGT]B)?$`
)

var (
Expand All @@ -40,10 +40,11 @@ func (e *Exporter) convArtiToPromNumber(artiNum string) (float64, error) {
logDbgKeyArtNum, artiNum,
)
err := fmt.Errorf(
`The string '%s' does not match pattern '%s'.`,
`the string '%s' does not match pattern '%s'.`,
artiNum,
pattNumber,
)

return 0, err
}

Expand Down
5 changes: 5 additions & 0 deletions collector/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func TestConvNum(t *testing.T) {
input: `1000GB`,
want: 1073741824000.0,
},
{
// https://github.com/peimanja/artifactory_exporter/pull/150#pullrequestreview-2422219410
input: `9999 KB`,
want: 10238976.0,
},
}
for _, tc := range tests {
got, err := fakeExporter.convArtiToPromNumber(tc.input)
Expand Down

0 comments on commit 149f078

Please sign in to comment.