From 673ba5a65ba82035e8d08b3cc10b747d573ab622 Mon Sep 17 00:00:00 2001 From: KAcper Perschke Date: Thu, 7 Nov 2024 22:42:48 +0100 Subject: [PATCH] convArtiToPromNumber use case (#150) The regular expression `pattNumber` did not recognise the word `1000GB`. --- collector/converter.go | 2 +- collector/converter_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/collector/converter.go b/collector/converter.go index d581598..0da6a46 100644 --- a/collector/converter.go +++ b/collector/converter.go @@ -21,7 +21,7 @@ func convArtiToPromBool(b bool) float64 { } const ( - pattNumber = `^(?P[[:digit:]]{1,3}(?:,[[:digit:]]{3})*(?:\.[[:digit:]]{1,2})?) ?(?P%|bytes|[KMGT]B)?$` + pattNumber = `^(?P[[:digit:]]{1,4}(?:,[[:digit:]]{3})*(?:\.[[:digit:]]{1,2})?) ?(?P%|bytes|[KMGT]B)?$` ) var ( diff --git a/collector/converter_test.go b/collector/converter_test.go index 22f066f..ab4a00d 100644 --- a/collector/converter_test.go +++ b/collector/converter_test.go @@ -64,6 +64,11 @@ func TestConvNum(t *testing.T) { input: `100 %`, want: 1.0, }, + { + // Detected during testing of https://github.com/peimanja/artifactory_exporter/pull/149 + input: `1000GB`, + want: 1073741824000.0, + }, } for _, tc := range tests { got, err := fakeExporter.convArtiToPromNumber(tc.input)