Skip to content

Commit

Permalink
Correct invalid monitor ID encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Fitzpatrick committed Apr 13, 2021
1 parent c213260 commit 08a5ab2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions internal/receiver/smartagentreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ package smartagentreceiver
import (
"context"
"fmt"
"net/url"
"os"
"path/filepath"
"reflect"
"regexp"
"runtime"
"sync"

Expand Down Expand Up @@ -62,6 +62,7 @@ var (
configureEnvironmentOnce sync.Once
saConfigProvider smartagentextension.SmartAgentConfigProvider
configureRusToZapOnce sync.Once
nonWordCharacters = regexp.MustCompile(`[^\w]+`)
)

func NewReceiver(logger *zap.Logger, config Config) *Receiver {
Expand Down Expand Up @@ -97,7 +98,7 @@ func (r *Receiver) Start(_ context.Context, host component.Host) error {

configCore := r.config.monitorConfig.MonitorConfigCore()
monitorType := configCore.Type
monitorName := url.PathEscape(r.config.Name())
monitorName := nonWordCharacters.ReplaceAllString(r.config.Name(), "")
configCore.MonitorID = types.MonitorID(monitorName)

configureRusToZapOnce.Do(func() {
Expand Down
2 changes: 1 addition & 1 deletion internal/receiver/smartagentreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestSmartAgentReceiver(t *testing.T) {
err := receiver.Start(context.Background(), componenttest.NewNopHost())
require.NoError(t, err)

assert.EqualValues(t, "smartagent%2Fvalid", cfg.monitorConfig.MonitorConfigCore().MonitorID)
assert.EqualValues(t, "smartagentvalid", cfg.monitorConfig.MonitorConfigCore().MonitorID)
monitor, isMonitor := receiver.monitor.(*cpu.Monitor)
require.True(t, isMonitor)

Expand Down

0 comments on commit 08a5ab2

Please sign in to comment.