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

use slogger on local server, add span_id id to logs, add kolide session id to logs #1446

Merged

Conversation

James-Pickett
Copy link
Contributor

@James-Pickett James-Pickett commented Nov 7, 2023

This PR:

  • updates localserver to use slogger
  • adds span id as ctx value for all spans which is picked up by multislogger middleware and added to logs
  • add launcher_run_id to logs, ulid to identify single run of launcher
  • add kolide session (saml id) to local server requests
  • update multislogger middleware to use unexported types for ctx keys (per golang documentation)

ee/localserver/krypto-ec-middleware.go Outdated Show resolved Hide resolved
ee/localserver/krypto-ec-middleware.go Outdated Show resolved Hide resolved
@James-Pickett James-Pickett marked this pull request as ready for review November 7, 2023 19:03
RebeccaMahany
RebeccaMahany previously approved these changes Nov 7, 2023
return
}

if resp != nil && resp.Body != nil {
resp.Body.Close()
}

level.Debug(e.logger).Log("msg", "Finished callback", "response-status", resp.Status)
e.slogger.Log(req.Context(), slog.LevelDebug, "finished callback",
"response-status", resp.Status,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"response-status", resp.Status,
"response_status", resp.Status,

RebeccaMahany
RebeccaMahany previously approved these changes Nov 7, 2023
kolideSessionId, ok := cmdReq.CallbackHeaders[multislogger.KolideSessionIdKey.String()]
if ok && len(kolideSessionId) > 0 {
span.SetAttributes(attribute.String(multislogger.KolideSessionIdKey.String(), kolideSessionId[0]))
r = r.WithContext(context.WithValue(r.Context(), multislogger.KolideSessionIdKey, kolideSessionId[0]))
Copy link
Contributor

Choose a reason for hiding this comment

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

This line feels awkward. It's pulling in request, context, and multislogger to stash a session key in the request context. I suspect it's correct, I don't know enough to know how to make it cleaner. But it feels awkward.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be less awkward if the expected header name was a constant here, it should not overload multislogger.KolideSessionIdKey. That brings in unneeded coupling

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated it so that we define the header key here as a constant. However, we still use the contextKey iota in multislogger to set context value

Copy link
Contributor

Choose a reason for hiding this comment

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

Yah. That part feels awkward, but I don't know enough to know how to fix it. We are, ultimately, trying to set internal state in context that multislogger uses. So it has to come from there.

But we should not stash http headers there

w.WriteHeader(http.StatusUnauthorized)
return
}

// set the kolide session id if it exists, this also the saml session id
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure kolide session id and saml session id are the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ask Chris and he confirmed it was the saml id

Copy link
Contributor

Choose a reason for hiding this comment

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

They might be the same now, but I'm not sure they'll be the same later. I'm suggesting we drop the comment about saml session id.

Comment on lines 18 to 20
// KolideSessionIdKey this the also the saml session id
KolideSessionIdKey contextKey = "X-Kolide-Session"
SpanIdKey contextKey = "span_id"
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels wrong. If these are context keys, they should probably be iotas. I don't think we should encode the header name here.

Copy link
Contributor Author

@James-Pickett James-Pickett Nov 7, 2023

Choose a reason for hiding this comment

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

now using iota, now the string of KolideSessionIdKey is kolide_session_id

Copy link
Contributor

@directionless directionless left a comment

Choose a reason for hiding this comment

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

Let's try

@James-Pickett James-Pickett added this pull request to the merge queue Nov 7, 2023
Merged via the queue into kolide:main with commit bc39add Nov 7, 2023
24 checks passed
@James-Pickett James-Pickett deleted the james/local-server-ctx-values-logging branch November 7, 2023 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants