Skip to content

Commit

Permalink
[receiver/vcenter] Refresh User Sessions (#13733)
Browse files Browse the repository at this point in the history
Attempt to refresh user sessions when the monitoring user gets logged out.
  • Loading branch information
schmikei committed Aug 31, 2022
1 parent 154ecfc commit e2da789
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
5 changes: 4 additions & 1 deletion receiver/vcenterreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ func newVcenterClient(c *Config) *vcenterClient {
// EnsureConnection will establish a connection to the vSphere SDK if not already established
func (vc *vcenterClient) EnsureConnection(ctx context.Context) error {
if vc.moClient != nil {
return nil
sessionActive, _ := vc.moClient.SessionManager.SessionIsActive(ctx)
if sessionActive {
return nil
}
}

sdkURL, err := vc.cfg.SDKUrl()
Expand Down
40 changes: 40 additions & 0 deletions receiver/vcenterreceiver/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ package vcenterreceiver // import github.com/open-telemetry/opentelemetry-collec

import (
"context"
"fmt"
"testing"

"github.com/stretchr/testify/require"
"github.com/vmware/govmomi"
"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/session"
"github.com/vmware/govmomi/simulator"
"github.com/vmware/govmomi/vim25"
"go.opentelemetry.io/collector/config/configtls"
)

func TestGetClusters(t *testing.T) {
Expand Down Expand Up @@ -64,3 +68,39 @@ func TestGetVMs(t *testing.T) {
require.NotEmpty(t, vms)
})
}

func TestSessionReestablish(t *testing.T) {
simulator.Test(func(ctx context.Context, c *vim25.Client) {
sm := session.NewManager(c)
moClient := &govmomi.Client{
Client: c,
SessionManager: sm,
}
pw, _ := simulator.DefaultLogin.Password()
client := vcenterClient{
vimDriver: c,
cfg: &Config{
Username: simulator.DefaultLogin.Username(),
Password: pw,
Endpoint: fmt.Sprintf("%s:https://%s", c.URL().Scheme, c.URL().Host),
TLSClientSetting: configtls.TLSClientSetting{
Insecure: true,
},
},
moClient: moClient,
}
err := sm.Logout(ctx)
require.NoError(t, err)

connected, err := client.moClient.SessionManager.SessionIsActive(ctx)
require.NoError(t, err)
require.False(t, connected)

err = client.EnsureConnection(ctx)
require.NoError(t, err)

connected, err = client.moClient.SessionManager.SessionIsActive(ctx)
require.NoError(t, err)
require.True(t, connected)
})
}
16 changes: 16 additions & 0 deletions unreleased/vcenter-refresh-sessions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: vcenterreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Re-establish sessions when running with particular TLS settings.

# One or more tracking issues related to the change
issues: [13447]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

0 comments on commit e2da789

Please sign in to comment.