Skip to content

Commit

Permalink
feat: add host and port getters so can be retrieved in the integratio…
Browse files Browse the repository at this point in the history
…ns when a connection query fails
  • Loading branch information
alvarocabanas committed Jun 1, 2021
1 parent 3f45fc5 commit c88cf78
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions jmx/jmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ var cmdErrC = make(chan error, cmdStdChanLen)
var cmdWarnC = make(chan string, cmdStdChanLen)
var done sync.WaitGroup

var jmxHost string
var jmxPort string

// jmxClientError error is returned when the nrjmx tool can not continue
type jmxClientError string

Expand Down Expand Up @@ -215,6 +218,9 @@ func openConnection(config *connectionConfig) (err error) {

cliCommand := config.command()

jmxHost = config.hostname
jmxPort = config.port

ctx, cancel = context.WithCancel(context.Background())
cmd = exec.CommandContext(ctx, cliCommand[0], cliCommand[1:]...)

Expand Down Expand Up @@ -396,3 +402,13 @@ func logAvailableWarnings(channel chan string) {
}
}
}

// HostName returns the host the nrjmx is connected to
func HostName() string {
return jmxHost
}

// Port returns the port the nrjmx is connected to
func Port() string {
return jmxPort
}
16 changes: 16 additions & 0 deletions jmx/jmx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ func TestQuery_WithSSL(t *testing.T) {
}

func TestOpen_WithNrjmx(t *testing.T) {
defer Close()

aux := os.Getenv("NR_JMX_TOOL")
require.NoError(t, os.Unsetenv("NR_JMX_TOOL"))

Expand Down Expand Up @@ -218,3 +220,17 @@ func Test_DefaultPath_IsCorrectForOs(t *testing.T) {
t.Fatal("unexpected value")
}
}

func TestHostName(t *testing.T) {
defer Close()
host := "a-host"
assert.NoError(t, OpenNoAuth(host, ""))
assert.Equal(t, host, HostName())
}

func TestPort(t *testing.T) {
defer Close()
port := "6666"
assert.NoError(t, OpenNoAuth("", port))
assert.Equal(t, port, Port())
}

0 comments on commit c88cf78

Please sign in to comment.