Skip to content

Commit

Permalink
add default readtimeout and writetimeout
Browse files Browse the repository at this point in the history
Signed-off-by: jiangyufang <[email protected]>
  • Loading branch information
J-lena authored and jiangyufang committed Jul 23, 2024
1 parent 49339e8 commit 4f0a5f7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile.Common
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ $(TOOLS_BIN_NAMES): $(TOOLS_BIN_DIR) $(TOOLS_MOD_DIR)/go.mod

.PHONY: test
test:
# $(GOTEST) $(GOTEST_OPT) -run TestSetDefaultConfig
$(GOTEST) $(GOTEST_OPT) ./...

.PHONY: test-with-cover
Expand Down
14 changes: 12 additions & 2 deletions receiver/otlpreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"net/url"
"path"
"time"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configgrpc"
Expand All @@ -17,8 +18,9 @@ import (

const (
// Protocol values.
protoGRPC = "protocols::grpc"
protoHTTP = "protocols::http"
protoGRPC = "protocols::grpc"
protoHTTP = "protocols::http"
defaultTimeout = 60 * time.Second
)

type HTTPConfig struct {
Expand Down Expand Up @@ -83,6 +85,14 @@ func (cfg *Config) Unmarshal(conf *confmap.Conf) error {
if cfg.HTTP.LogsURLPath, err = sanitizeURLPath(cfg.HTTP.LogsURLPath); err != nil {
return err
}
//set default server config value
if cfg.HTTP.ReadTimeout == 0 {
cfg.HTTP.ReadTimeout = defaultTimeout
}

if cfg.HTTP.WriteTimeout == 0 {
cfg.HTTP.WriteTimeout = defaultTimeout
}
}

return nil
Expand Down
11 changes: 11 additions & 0 deletions receiver/otlpreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ func TestUnmarshalConfig(t *testing.T) {

}

func TestSetDefaultConfig(t *testing.T) {
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
require.NoError(t, err)
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.NoError(t, cm.Unmarshal(&cfg))
assert.Equal(t, 60*time.Second, (cfg.(*Config)).HTTP.WriteTimeout)
assert.Equal(t, 60*time.Second, (cfg.(*Config)).HTTP.WriteTimeout)

}

func TestUnmarshalConfigUnix(t *testing.T) {
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "uds.yaml"))
require.NoError(t, err)
Expand Down

0 comments on commit 4f0a5f7

Please sign in to comment.