diff --git a/pkg/license/aggregator.go b/pkg/license/aggregator.go index 6681ef7ff0..103b48ff2f 100644 --- a/pkg/license/aggregator.go +++ b/pkg/license/aggregator.go @@ -207,8 +207,13 @@ var maxHeapSizeRe = regexp.MustCompile(`-Xmx([0-9]+)([gGmMkK]?)(?:\s.*|$)`) // memFromJavaOpts extracts the maximum Java heap size from a Java options string, multiplies the value by 2 // (giving twice the JVM memory to the container is a common thing people do) // and converts it to a resource.Quantity +// If no value is found the function returns the 0 value. func memFromJavaOpts(javaOpts string) (resource.Quantity, error) { match := maxHeapSizeRe.FindStringSubmatch(javaOpts) + if match == nil { + // Xmx is not set, return a 0 quantity + return resource.Quantity{}, nil + } if len(match) != 3 { return resource.Quantity{}, errors.Errorf("cannot extract max jvm heap size from %s", javaOpts) } diff --git a/pkg/license/aggregator_test.go b/pkg/license/aggregator_test.go index 5afef02281..f0368f1f72 100644 --- a/pkg/license/aggregator_test.go +++ b/pkg/license/aggregator_test.go @@ -66,27 +66,6 @@ func TestMemFromJavaOpts(t *testing.T) { actual: "-Xmx1048576", expected: resource.MustParse("2Mi"), }, - { - name: "without value", - actual: "-XmxM", - isErr: true, - }, - { - name: "with an invalid Xmx", - actual: "-XMX1k", - isErr: true, - }, - { - name: "with an invalid unit", - actual: "-Xmx64GB", - isErr: true, - }, - { - name: "without xmx", - actual: "-Xms1k", - expected: resource.MustParse("16777216k"), - isErr: true, - }, { name: "with trailing spaces at the end", actual: "-Xms1k -Xmx8388608k ", @@ -97,6 +76,11 @@ func TestMemFromJavaOpts(t *testing.T) { actual: " -Xms1k -Xmx8388608k", expected: resource.MustParse("16777216Ki"), }, + { + name: "no memory setting detected", + actual: "-Dlog4j2.formatMsgNoLookups=true", + expected: resource.MustParse("0"), + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {