From 149f078040c24036eafcb1c6ba0dcdb5fb9bbec2 Mon Sep 17 00:00:00 2001 From: KAcper Perschke Date: Fri, 6 Dec 2024 16:21:42 +0100 Subject: [PATCH] Little proffing of convArtiToPromNumber. (#151) A Peiman wrote in https://github.com/peimanja/artifactory_exporter/pull/150#pullrequestreview-2422219410 Co-authored-by: Peiman Jafari <18074432+peimanja@users.noreply.github.com> --- collector/converter.go | 5 +++-- collector/converter_test.go | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/collector/converter.go b/collector/converter.go index 0da6a46..d571577 100644 --- a/collector/converter.go +++ b/collector/converter.go @@ -21,7 +21,7 @@ func convArtiToPromBool(b bool) float64 { } const ( - pattNumber = `^(?P[[:digit:]]{1,4}(?:,[[:digit:]]{3})*(?:\.[[:digit:]]{1,2})?) ?(?P%|bytes|[KMGT]B)?$` + pattNumber = `^(?P[[:digit:]]{1,3}(?:[[:digit:]]|(?:,[[:digit:]]{3})*(?:\.[[:digit:]]{1,2}))?) ?(?P%|bytes|[KMGT]B)?$` ) var ( @@ -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 } diff --git a/collector/converter_test.go b/collector/converter_test.go index ab4a00d..ef4a529 100644 --- a/collector/converter_test.go +++ b/collector/converter_test.go @@ -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)