Skip to content

Commit

Permalink
opamp config validate remote_configuration_directory existence
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Porter <[email protected]>
  • Loading branch information
portertech committed Oct 6, 2023
1 parent 8fb2c65 commit f133752
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 7 additions & 0 deletions pkg/extension/opampextension/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package opampextension

import (
"errors"
"fmt"
"os"

"github.com/oklog/ulid/v2"
"go.opentelemetry.io/collector/component"
Expand Down Expand Up @@ -61,5 +63,10 @@ func (cfg *Config) Validate() error {
return errors.New("opamp remote_configuration_directory must be provided")
}

d := cfg.RemoteConfigurationDirectory
if _, err := os.Stat(d); err != nil {
return fmt.Errorf("opamp remote_configuration_directory %s must be readable: %v", d, err)
}

return nil
}
14 changes: 13 additions & 1 deletion pkg/extension/opampextension/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package opampextension

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

Expand Down Expand Up @@ -60,9 +62,19 @@ func TestConfigValidate(t *testing.T) {
err := cfg.Validate()
require.Error(t, err)
assert.Equal(t, "opamp remote_configuration_directory must be provided", err.Error())

cfg.RemoteConfigurationDirectory = "/tmp/opamp.d"
err = cfg.Validate()
require.NoError(t, err)
assert.Equal(t, "opamp remote_configuration_directory /tmp/opamp.d must be readable: stat /tmp/opamp.d: no such file or directory", err.Error())

d, err := ioutil.TempDir("", "opamp.d")
assert.NoError(t, err)
defer os.RemoveAll(d)

cfg.RemoteConfigurationDirectory = d
err = cfg.Validate()
assert.NoError(t, err)

cfg.InstanceUID = "01BX5ZZKBKACTAV9WEVGEMMVRZFAIL"
err = cfg.Validate()
require.Error(t, err)
Expand Down
4 changes: 1 addition & 3 deletions pkg/extension/opampextension/opamp_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,7 @@ func newOpampAgent(cfg *Config, logger *zap.Logger, build component.BuildInfo, r
}

func (o *opampAgent) getAgentCapabilities() protobufs.AgentCapabilities {
var c protobufs.AgentCapabilities

c = protobufs.AgentCapabilities_AgentCapabilities_ReportsEffectiveConfig
c := protobufs.AgentCapabilities_AgentCapabilities_ReportsEffectiveConfig

if o.cfg.AcceptsRemoteConfiguration {
c = c |
Expand Down

0 comments on commit f133752

Please sign in to comment.