Skip to content

Commit

Permalink
Revert how the args are parsed on windows (#6431)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan <[email protected]>
  • Loading branch information
bogdandrutu authored Oct 28, 2022
1 parent 82787ad commit 525b2c7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .chloggen/revertargs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 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. otlpreceiver)
component: service

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix running collector as a windows service.

# One or more tracking issues or pull requests related to the change
issues: [6433]
11 changes: 6 additions & 5 deletions service/collector_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"flag"
"fmt"
"os"
"time"

"go.uber.org/zap"
Expand Down Expand Up @@ -56,11 +57,6 @@ func (s *windowsService) Execute(args []string, requests <-chan svc.ChangeReques
return false, 1501 // 1501: ERROR_EVENTLOG_CANT_START
}

// Parse all the flags manually.
if err = s.flags.Parse(args[1:]); err != nil {
return false, 1639 // 1639: ERROR_INVALID_COMMAND_LINE
}

colErrorChannel := make(chan error, 1)

changes <- svc.Status{State: svc.StartPending}
Expand Down Expand Up @@ -93,6 +89,11 @@ func (s *windowsService) Execute(args []string, requests <-chan svc.ChangeReques
}

func (s *windowsService) start(elog *eventlog.Log, colErrorChannel chan error) error {
// Parse all the flags manually.
if err := s.flags.Parse(os.Args[1:]); err != nil {
return err
}

if err := featuregate.GetRegistry().Apply(getFeatureGatesFlag(s.flags)); err != nil {
return err
}
Expand Down
7 changes: 6 additions & 1 deletion service/collector_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package service

import (
"os"
"path/filepath"
"testing"

Expand All @@ -30,6 +31,10 @@ import (
)

func TestNewSvcHandler(t *testing.T) {
oldArgs := os.Args
defer func() { os.Args = oldArgs }()
os.Args = []string{"otelcol", "--config", filepath.Join("testdata", "otelcol-nop.yaml")}

factories, err := componenttest.NopFactories()
require.NoError(t, err)

Expand All @@ -40,7 +45,7 @@ func TestNewSvcHandler(t *testing.T) {
changes := make(chan svc.Status)
go func() {
defer close(colDone)
ssec, errno := s.Execute([]string{"otelcol", "--config", filepath.Join("testdata", "otelcol-nop.yaml")}, requests, changes)
ssec, errno := s.Execute([]string{"svc name"}, requests, changes)
assert.Equal(t, uint32(0), errno)
assert.False(t, ssec)
}()
Expand Down

0 comments on commit 525b2c7

Please sign in to comment.