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

fix: Do not log wakeup error when app is in stopping state #2145

Merged
merged 3 commits into from
Nov 20, 2024
Merged
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
11 changes: 6 additions & 5 deletions internal/pkg/service/appsproxy/dataapps/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import (

const (
// maxCacheExpiration is the maximum duration for which an old AppConfig of a data app is cached.
maxCacheExpiration = time.Hour
attrProjectID = "proxy.app.projectId"
attrAppID = "proxy.app.id"
attrAppName = "proxy.app.name"
attrAppUpstream = "proxy.app.upstream"
maxCacheExpiration = time.Hour
attrSandboxesServiceStatusCode = "proxy.sandboxesService.statusCode"
attrProjectID = "proxy.app.projectId"
attrAppID = "proxy.app.id"
attrAppName = "proxy.app.name"
attrAppUpstream = "proxy.app.upstream"
)

type AppID string
Expand Down
16 changes: 15 additions & 1 deletion internal/pkg/service/appsproxy/dataapps/api/wakeup.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package api

import "github.com/keboola/go-client/pkg/request"
import (
"context"

"github.com/keboola/go-client/pkg/request"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)

type wakeupBody struct {
DesiredState string `json:"desiredState"`
Expand All @@ -9,6 +15,14 @@ type wakeupBody struct {
func (a *API) WakeupApp(appID AppID) request.APIRequest[request.NoResult] {
return request.NewAPIRequest(request.NoResult{}, a.newRequest().
WithError(&Error{}).
WithOnError(func(ctx context.Context, response request.HTTPResponse, err error) error {
span := trace.SpanFromContext(ctx)
attrs := []attribute.KeyValue{
attribute.Int(attrSandboxesServiceStatusCode, response.StatusCode()),
}
span.SetAttributes(attrs...)
return nil
}).
WithPatch("apps/{appId}").
AndPathParam("appId", appID.String()).
WithJSONBody(wakeupBody{
Expand Down
11 changes: 9 additions & 2 deletions internal/pkg/service/appsproxy/dataapps/wakeup/wakeup.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import (

// Interval sets how often the proxy sends wakeup request to sandboxes service.
// If the last notification for the app was less than this Interval ago then the notification is skipped.
const Interval = time.Second
const (
Interval = time.Second
wakeupErrorToBeSkipped = `can't have desired state "running". Currently is in state: "stopping", desired state: "stopped"`
)

type Manager struct {
clock clock.Clock
Expand Down Expand Up @@ -68,7 +71,11 @@ func (l *Manager) Wakeup(ctx context.Context, appID api.AppID) error {
item.nextRequestAfter = now.Add(Interval)

// Send the notification
if _, err := l.api.WakeupApp(appID).Send(ctx); err != nil {
_, err := l.api.WakeupApp(appID).Send(ctx)
// If it does not succeed but app is currently stopping do not log it as error, log only other errors
jachym-tousek-keboola marked this conversation as resolved.
Show resolved Hide resolved
// Instead of implementing state machine as in sandboxes service, we want to skip valid state that the
// pod is dealocating and we want to wait till pod is `stopped` and we can `start` the pod again.
if err != nil && err.Error() != wakeupErrorToBeSkipped {
l.logger.Errorf(ctx, `failed sending wakeup request to Sandboxes Service about for app "%s": %s`, appID, err.Error())
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

const (
notifyRequestTimeout = 5 * time.Second
wakeupRequestTimeout = 15 * time.Second
wakeupRequestTimeout = 60 * time.Second
attrWakeupReason = "proxy.wakeup.reason"
attrWebsocket = "proxy.websocket"
)
Expand Down