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

Add some logs to the remote flare consumer #1441

Merged
merged 4 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion cmd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func runLauncher(ctx context.Context, cancel func(), slogger, systemSlogger *mul
actionsQueue.RegisterActor(acceleratecontrolconsumer.AccelerateControlSubsystem, acceleratecontrolconsumer.New(k))

// register flare consumer
actionsQueue.RegisterActor(flareconsumer.FlareSubsystem, flareconsumer.New(logger, k))
actionsQueue.RegisterActor(flareconsumer.FlareSubsystem, flareconsumer.New(k))

// create notification consumer
notificationConsumer, err := notificationconsumer.NewNotifyConsumer(
Expand Down
18 changes: 10 additions & 8 deletions ee/control/consumers/flareconsumer/flareconsumer.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package flareconsumer

Check failure on line 1 in ee/control/consumers/flareconsumer/flareconsumer.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest)

: # github.com/kolide/launcher/ee/control/consumers/flareconsumer [github.com/kolide/launcher/ee/control/consumers/flareconsumer.test]

Check failure on line 1 in ee/control/consumers/flareconsumer/flareconsumer.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

: # github.com/kolide/launcher/ee/control/consumers/flareconsumer [github.com/kolide/launcher/ee/control/consumers/flareconsumer.test]

import (
"context"
Expand All @@ -6,11 +6,9 @@
"errors"
"fmt"
"io"
"log/slog"
"time"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"

"github.com/kolide/launcher/pkg/agent/types"
"github.com/kolide/launcher/pkg/debug/checkups"
"github.com/kolide/launcher/pkg/debug/shipper"
Expand All @@ -26,7 +24,6 @@
lastFlareTime time.Time
flarer flarer
knapsack types.Knapsack
logger log.Logger
// newFlareStream is assigned to a field so it can be mocked in tests
newFlareStream func(note, uploadRequestURL string) (io.WriteCloser, error)
}
Expand All @@ -41,23 +38,24 @@
return checkups.RunFlare(ctx, k, flareStream, checkups.InSituEnvironment)
}

func New(logger log.Logger, knapsack types.Knapsack) *FlareConsumer {
func New(knapsack types.Knapsack) *FlareConsumer {
return &FlareConsumer{
flarer: &FlareRunner{},
knapsack: knapsack,
logger: logger,
newFlareStream: func(note, uploadRequestURL string) (io.WriteCloser, error) {
return shipper.New(knapsack, shipper.WithNote(note), shipper.WithUploadRequestURL(uploadRequestURL))
},
}
}

func (fc *FlareConsumer) Do(data io.Reader) error {
// slog needs a ctx
RebeccaMahany marked this conversation as resolved.
Show resolved Hide resolved
ctx := context.TODO()

timeSinceLastFlare := time.Since(fc.lastFlareTime)

if timeSinceLastFlare < minFlareInterval {
level.Info(fc.logger).Log(
"msg", "skipping flare, run too recently",
fc.knapsack.Slogger().Log(ctx, slog.LevelInfo, "skipping flare, run too recently",
"min_flare_interval", fmt.Sprintf("%v minutes", minFlareInterval.Minutes()),
"time_since_last_flare", fmt.Sprintf("%v minutes", timeSinceLastFlare.Minutes()),
)
Expand All @@ -81,6 +79,10 @@
return fmt.Errorf("failed to decode key-value json: %w", err)
}

fc.knapsack.Slogger().Log(ctx, slog.LevelInfo, "Recieved remote flare request",
directionless marked this conversation as resolved.
Show resolved Hide resolved
"note", flareData.Note,
)

flareStream, err := fc.newFlareStream(flareData.Note, flareData.UploadRequestURL)
if err != nil {
return fmt.Errorf("failed to create flare stream: %w", err)
Expand Down
Loading