Skip to content

jmxreceiver: update integration test for new release #5429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions receiver/jmxreceiver/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,55 @@ import (
"go.uber.org/zap/zaptest/observer"
)

var jmxJarReleases = map[string]string{
"1.0.0-alpha": "https://repo1.maven.org/maven2/io/opentelemetry/contrib/opentelemetry-java-contrib-jmx-metrics/1.0.0-alpha/opentelemetry-java-contrib-jmx-metrics-1.0.0-alpha.jar",
"1.4.0-alpha": "https://repo1.maven.org/maven2/io/opentelemetry/contrib/opentelemetry-jmx-metrics/1.4.0-alpha/opentelemetry-jmx-metrics-1.4.0-alpha.jar",
type testInfo struct{ version, jarUrl, scriptName, expectedVersion, jarPath string }

var tests = []testInfo{
{
version: "1.0.0-alpha",
jarUrl: "https://repo1.maven.org/maven2/io/opentelemetry/contrib/opentelemetry-java-contrib-jmx-metrics/1.0.0-alpha/opentelemetry-java-contrib-jmx-metrics-1.0.0-alpha.jar",
scriptName: "script1_4.groovy",
expectedVersion: "1.0.0-alpha",
},
{
version: "1.4.0-alpha",
jarUrl: "https://repo1.maven.org/maven2/io/opentelemetry/contrib/opentelemetry-jmx-metrics/1.4.0-alpha/opentelemetry-jmx-metrics-1.4.0-alpha.jar",
scriptName: "script1_4.groovy",
expectedVersion: "1.0.0-alpha",
},
{
version: "1.6.0-alpha",
jarUrl: "https://github.com/open-telemetry/opentelemetry-java-contrib/releases/download/v1.6.0/opentelemetry-jmx-metrics.jar",
scriptName: "script1_6.groovy",
expectedVersion: "1.6.0",
},
}

type JMXIntegrationSuite struct {
suite.Suite
VersionToJar map[string]string
tests []*testInfo
}

func TestJMXIntegration(t *testing.T) {
suite.Run(t, new(JMXIntegrationSuite))
var ts []*testInfo
for _, test := range tests {
t := test
ts = append(ts, &t)
}
suite.Run(t, &JMXIntegrationSuite{tests: ts})
}

func (suite *JMXIntegrationSuite) SetupSuite() {
suite.VersionToJar = make(map[string]string)
for version, url := range jmxJarReleases {
jarPath, err := downloadJMXMetricGathererJAR(url)
for _, test := range suite.tests {
jarPath, err := downloadJMXMetricGathererJAR(test.jarUrl)
require.NoError(suite.T(), err)
suite.VersionToJar[version] = jarPath
require.NotEmpty(suite.T(), jarPath)
test.jarPath = jarPath
}
}

func (suite *JMXIntegrationSuite) TearDownSuite() {
for _, path := range suite.VersionToJar {
require.NoError(suite.T(), os.Remove(path))
for _, test := range suite.tests {
require.NoError(suite.T(), os.Remove(test.jarPath))
}
}

Expand Down Expand Up @@ -134,11 +157,10 @@ func getLogsOnFailure(t *testing.T, logObserver *observer.ObservedLogs) {
}

func (suite *JMXIntegrationSuite) TestJMXReceiverHappyPath() {

for version, jar := range suite.VersionToJar {
for _, test := range suite.tests {
t := suite.T()
// Run one test per JMX receiver version we're integrating with.
t.Run(version, func(t *testing.T) {
t.Run(test.version, func(t *testing.T) {
cassandra := cassandraContainer(t)
defer cassandra.Terminate(context.Background())
hostname, err := cassandra.Host(context.Background())
Expand All @@ -154,8 +176,8 @@ func (suite *JMXIntegrationSuite) TestJMXReceiverHappyPath() {
cfg := &Config{
CollectionInterval: 100 * time.Millisecond,
Endpoint: fmt.Sprintf("%v:7199", hostname),
JARPath: jar,
GroovyScript: path.Join(".", "testdata", "script.groovy"),
JARPath: test.jarPath,
GroovyScript: path.Join(".", "testdata", test.scriptName),
OTLPExporterConfig: otlpExporterConfig{
Endpoint: "127.0.0.1:0",
TimeoutSettings: exporterhelper.TimeoutSettings{
Expand Down Expand Up @@ -221,7 +243,7 @@ func (suite *JMXIntegrationSuite) TestJMXReceiverHappyPath() {

ilm := rm.InstrumentationLibraryMetrics().At(0)
require.Equal(t, "io.opentelemetry.contrib.jmxmetrics", ilm.InstrumentationLibrary().Name())
require.Equal(t, "1.0.0-alpha", ilm.InstrumentationLibrary().Version())
require.Equal(t, test.expectedVersion, ilm.InstrumentationLibrary().Version())

met := ilm.Metrics().At(0)

Expand Down
24 changes: 24 additions & 0 deletions receiver/jmxreceiver/testdata/script1_6.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

def storageLoad = otel.mbean("org.apache.cassandra.metrics:type=Storage,name=Load")
otel.instrument(storageLoad, "cassandra.storage.load",
"Size, in bytes, of the on disk data size this node manages",
"By", [
"myKey": { _ -> "myVal" },
"${System.properties['my.label.name']}": { _ -> System.properties["my.label.value"] },
"${System.properties['my.other.label.name']}": { _ -> System.properties["my.other.label.value"] },
], "Count", otel.&longUpDownCounterCallback)