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 GetLogs parsing to log object #9985

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/server/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,10 @@ func (ls LogService) authPipelineLogs(ctx context.Context, pipeline, project str
return pass
}
}
var pass bool
err := ls.AuthServer.CheckRepoIsAuthorized(ctx, repo, auth.Permission_REPO_READ)
if err != nil && !auth.IsErrNotActivated(err) {
pass := true
if err := ls.AuthServer.CheckRepoIsAuthorized(ctx, repo, auth.Permission_REPO_READ); err != nil && !auth.IsErrNotActivated(err) {
log.Info(ctx, "unauthorized to retrieve logs for pipeline", zap.Error(err), zap.String("pipeline", project+"@"+pipeline))
pass = false
} else {
pass = true
}
if cache != nil {
cache[repo.String()] = pass
Expand Down Expand Up @@ -479,9 +476,19 @@ func (a *adapter) publish(ctx context.Context, entry loki.Entry) (bool, error) {
if err := msg.Object.UnmarshalJSON([]byte(entry.Line)); err != nil {
log.Error(ctx, "failed to unmarshal json into protobuf Struct", zap.Error(err), zap.String("line", entry.Line))
msg.Object = nil
} else if val := msg.Object.Fields["time"].GetStringValue(); val != "" {
if t, err := time.Parse(time.RFC3339Nano, val); err == nil {
msg.NativeTimestamp = timestamppb.New(t)
} else {
if val := msg.Object.Fields["time"].GetStringValue(); val != "" {
if t, err := time.Parse(time.RFC3339Nano, val); err == nil {
msg.NativeTimestamp = timestamppb.New(t)
}
}
if val := msg.Object.Fields["log"].GetStringValue(); val != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the "log" field? I think you're hitting the case where Loki is misconfigured and responses are wrapped inside this: https://docs.docker.com/config/containers/logging/json-file/

We need to handle this higher up, when we first get the line back from Loki. It also means you're using a weird dev environment if you're running into this.

obj := new(structpb.Struct)
if err := obj.UnmarshalJSON([]byte(val)); err != nil {
log.Error(ctx, "failed to unmarshal json into protobuf Struct", zap.Error(err), zap.String("log", val))
} else {
msg.Object = obj
}
}
}
msg.PpsLogMessage = new(pps.LogMessage)
Expand Down