Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference #883: env timeout open k8s logstream #1154

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 19 additions & 1 deletion pkg/workceptor/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,24 @@
return inner
}

func GetTimeoutOpenLogstream(kw *KubeUnit) int {
// RECEPTOR_OPEN_LOGSTREAM_TIMEOUT
// default: 1
openLogStreamTimeout := 1
envTimeout := os.Getenv("RECEPTOR_OPEN_LOGSTREAM_TIMEOUT")
if envTimeout != "" {
var err error
openLogStreamTimeout, err = strconv.Atoi(envTimeout)
if err != nil {
// ignore error, use default
kw.GetWorkceptor().nc.GetLogger().Warning("Invalid value for RECEPTOR_OPEN_LOGSTREAM_TIMEOUT: %s. Ignoring", envTimeout)
openLogStreamTimeout = 1
}
}
kw.GetWorkceptor().nc.GetLogger().Debug("RECEPTOR_OPEN_LOGSTREAM_TIMEOUT: %d", openLogStreamTimeout)
return openLogStreamTimeout

Check failure on line 247 in pkg/workceptor/kubernetes.go

View workflow job for this annotation

GitHub Actions / lint-receptor

return with no blank line before (nlreturn)
}

func (kw *KubeUnit) kubeLoggingConnectionHandler(timestamps bool, sinceTime time.Time) (io.ReadCloser, error) {
var logStream io.ReadCloser
var err error
Expand Down Expand Up @@ -257,7 +275,7 @@
retries,
err,
)
time.Sleep(time.Second)
time.Sleep(time.Duration(GetTimeoutOpenLogstream(kw)) * time.Second)

Check warning on line 278 in pkg/workceptor/kubernetes.go

View check run for this annotation

Codecov / codecov/patch

pkg/workceptor/kubernetes.go#L278

Added line #L278 was not covered by tests
}
if err != nil {
errMsg := fmt.Sprintf("Error opening log stream for pod %s/%s. Error: %s", podNamespace, podName, err)
Expand Down
46 changes: 46 additions & 0 deletions pkg/workceptor/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,52 @@
}
}

func TestGetTimeoutOpenLogstream(t *testing.T) {
const envVariable string = "RECEPTOR_OPEN_LOGSTREAM_TIMEOUT"

kw, err := startNetceptorNodeWithWorkceptor()
if err != nil {
t.Fatal(err)
}

tests := []struct {
name string
envValue string
want int
}{
{
name: "No env value set",
envValue: "",
want: 1,
},
{
name: "Env value set incorrectly",
envValue: "text instead of int",
want: 1,
},
{
name: "Env value set correctly",
envValue: "2",
want: 2,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.envValue != "" {
os.Setenv(envVariable, tt.envValue)
defer os.Unsetenv(envVariable)
} else {
os.Unsetenv(envVariable)
}

if got := workceptor.GetTimeoutOpenLogstream(kw); got != tt.want {
t.Errorf("GetTimeoutOpenLogstream() = %v, want %v", got, tt.want)
}
})
}

}

Check failure on line 148 in pkg/workceptor/kubernetes_test.go

View workflow job for this annotation

GitHub Actions / lint-receptor

unnecessary trailing newline (whitespace)

func TestParseTime(t *testing.T) {
type args struct {
s string
Expand Down
Loading