Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bc15663
chore:removing collector name from credential path for sumologic
pankaj101A Sep 3, 2025
31076ad
SUMO-268424:test case
pankaj101A Sep 5, 2025
b0bb400
SUMO-268424:using logger
pankaj101A Sep 5, 2025
bf65d5e
chore:changelog
pankaj101A Sep 8, 2025
5e65f86
Merge branch 'main' into SUMO-268424
pankaj101A Sep 9, 2025
2e8520c
chore: fix test case lint
pankaj101A Sep 10, 2025
9d570cb
Merge branch 'SUMO-268424' of https://github.com/pankaj101A/pankaj-op…
pankaj101A Sep 10, 2025
f6cdb07
Merge branch 'main' into SUMO-268424
pankaj101A Sep 10, 2025
171fc7c
Merge branch 'main' into SUMO-268424
pankaj101A Sep 16, 2025
4f70773
chore: fix test case lint
pankaj101A Sep 17, 2025
cdc2bfe
Merge branch 'SUMO-268424' of https://github.com/pankaj101A/pankaj-op…
pankaj101A Sep 17, 2025
db8f28d
Merge branch 'main' into SUMO-268424
pankaj101A Sep 17, 2025
c27fa31
Merge branch 'main' into SUMO-268424
pankaj101A Sep 18, 2025
ad3f8bd
chore: fix test
pankaj101A Sep 18, 2025
3f21167
Merge branch 'SUMO-268424' of https://github.com/pankaj101A/pankaj-op…
pankaj101A Sep 18, 2025
56beb59
chore: reducing logs
pankaj101A Sep 19, 2025
c605256
chore: increment req count to consider health event loop start
pankaj101A Sep 22, 2025
113abbe
Merge branch 'main' into SUMO-268424
pankaj101A Sep 23, 2025
5bedede
Merge branch 'main' into SUMO-268424
pankaj101A Sep 23, 2025
44bc4bf
SUMO-268424:revert race condition req count
pankaj101A Sep 23, 2025
b79069b
chore:closing extension heartloop first
pankaj101A Sep 24, 2025
007750e
Merge branch 'main' into SUMO-268424
pankaj101A Sep 24, 2025
b03829d
Merge branch 'main' into SUMO-268424
pankaj101A Sep 24, 2025
879c9b9
Merge branch 'main' into SUMO-268424
pankaj101A Sep 24, 2025
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
27 changes: 27 additions & 0 deletions .chloggen/sumologicextension-v2-credentials.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "removing collector name from credential path for sumologic extension"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [42511]

# (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:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
39 changes: 34 additions & 5 deletions extension/sumologicextension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ type SumologicExtension struct {
stickySessionCookieLock sync.RWMutex
stickySessionCookie string

closeChan chan struct{}
closeOnce sync.Once
backOff *backoff.ExponentialBackOff
id component.ID
closeChan chan struct{}
closeOnce sync.Once
backOff *backoff.ExponentialBackOff
id component.ID
collectorCredentials credentials.CollectorCredentials
}

const (
Expand Down Expand Up @@ -129,7 +130,16 @@ func newSumologicExtension(conf *Config, logger *zap.Logger, id component.ID, bu
var (
collectorName string
hashKey = createHashKey(conf)
hashKeyV2 = createHashKeyV2(conf)
)

_, err = credentialsStore.Get(hashKeyV2)
if err != nil {
logger.Info("credentials not found, trying legacy credentials", zap.Error(err))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.Info("credentials not found, trying legacy credentials", zap.Error(err))
logger.Info("credentials not found, using legacy credentials", zap.Error(err))

Nit: When I see the word trying I assume some other work will happen, but that's not the case. I think this wording may be more clear. Feel free to drop.

} else {
logger.Debug("v2 credentials found")
hashKey = hashKeyV2
}
if conf.CollectorName == "" {
// If collector name is not set by the user, check if the collector was restarted
// and that we can reuse collector name save in credentials store.
Expand Down Expand Up @@ -178,6 +188,13 @@ func createHashKey(conf *Config) string {
)
}

func createHashKeyV2(conf *Config) string {
return fmt.Sprintf("%s%s",
conf.Credentials.InstallationToken,
strings.TrimSuffix(conf.APIBaseURL, "/"),
)
}

func (se *SumologicExtension) Start(ctx context.Context, host component.Host) error {
var err error
se.host = host
Expand All @@ -191,6 +208,7 @@ func (se *SumologicExtension) Start(ctx context.Context, host component.Host) er
}

colCreds, err := se.getCredentials(ctx)
se.collectorCredentials = colCreds
if err != nil {
return err
}
Expand Down Expand Up @@ -218,9 +236,20 @@ func (se *SumologicExtension) Start(ctx context.Context, host component.Host) er
return nil
}

// Shutdown is invoked during service shutdown.
func (se *SumologicExtension) Shutdown(ctx context.Context) error {
se.closeOnce.Do(func() { close(se.closeChan) })

hashKeyV2 := createHashKeyV2(se.conf)
_, err := se.credentialsStore.Get(hashKeyV2)
se.logger.Debug("Shutting down Sumo Logic extension migrating to hashkeyV2 ")
if err != nil {
se.logger.Warn("Failed to get collector v2 credentials on shutdown, migrating to v2", zap.Error(err))
err := se.credentialsStore.Store(hashKeyV2, se.collectorCredentials)
if err != nil {
se.logger.Warn("Failed to migrate collector credentials to v2 on shutdown", zap.Error(err))
}
}

select {
case <-ctx.Done():
return ctx.Err()
Expand Down
86 changes: 86 additions & 0 deletions extension/sumologicextension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,92 @@ func TestStoreCredentials_PreexistingCredentialsAreUsed(t *testing.T) {
require.EqualValues(t, 2, atomic.LoadInt32(&reqCount))
}

func TestStoreCredentials_V2CredentialsAreUsed(t *testing.T) {
t.Parallel()

getServer := func() *httptest.Server {
return httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, req *http.Request) {
switch req.URL.Path {
case heartbeatURL:
w.WriteHeader(http.StatusNoContent)
case metadataURL:
w.WriteHeader(http.StatusOK)
default:
w.WriteHeader(http.StatusInternalServerError)
}
}))
}

getConfig := func(url string) *Config {
cfg := createDefaultConfig().(*Config)
cfg.CollectorName = "collector_name"
cfg.APIBaseURL = url
cfg.Credentials.InstallationToken = "dummy_install_token"
return cfg
}

logger, err := zap.NewDevelopment()
require.NoError(t, err)

dir := t.TempDir()
t.Logf("Using dir: %s", dir)

store, err := credentials.NewLocalFsStore(
credentials.WithCredentialsDirectory(dir),
credentials.WithLogger(logger),
)
require.NoError(t, err)

srv := getServer()
t.Cleanup(func() { srv.Close() })

cfg := getConfig(srv.URL)
cfg.CollectorCredentialsDirectory = dir

hashKey := createHashKey(cfg)

require.NoError(t,
store.Store(hashKey, credentials.CollectorCredentials{
CollectorName: "collector_name",
Credentials: api.OpenRegisterResponsePayload{
CollectorCredentialID: "collectorId",
CollectorCredentialKey: "collectorKey",
CollectorID: "id",
},
}),
)

se, err := newSumologicExtension(cfg, logger, component.NewID(metadata.Type), "1.0.0")
require.NoError(t, err)

fileName, err := credentials.HashKeyToFilename(hashKey)
require.NoError(t, err)
credsPath := path.Join(dir, fileName)
// Credentials file exists before starting the extension because we created
// it directly via store.Store()
require.FileExists(t, credsPath)

require.NoError(t, se.Start(t.Context(), componenttest.NewNopHost()))
require.NoError(t, se.Shutdown(t.Context()))
require.FileExists(t, credsPath)
hashKeyV2 := createHashKeyV2(cfg)
v2Creds, _ := store.Get(hashKeyV2)

fileName, err = credentials.HashKeyToFilename(hashKeyV2)
require.NoError(t, err)
credsPath = path.Join(dir, fileName)
require.Equal(t, credentials.CollectorCredentials{
CollectorName: "collector_name",
Credentials: api.OpenRegisterResponsePayload{
CollectorCredentialID: "collectorId",
CollectorCredentialKey: "collectorKey",
CollectorID: "id",
},
}, v2Creds)
require.FileExists(t, credsPath)
}

func TestLocalFSCredentialsStore_WorkCorrectlyForMultipleExtensions(t *testing.T) {
t.Parallel()

Expand Down
Loading