Add events on session activation and connection authz/close (#2215)
* Add events on session activation and connection authz/close * Only send success event on actual success
This commit is contained in:
1 parent
c31b8a4383
commit
f5bf3b2c0c
3 files changed
+21
-11
No files matched your search
@@ -194,6 +194,7 @@ func (w *Worker) handleProxy(listenerCfg *listenerutil.ListenerConfig) (http.Han
|
||||
}
|
||||
return
|
||||
}
|
||||
event.WriteSysEvent(ctx, op, "session successfully activated", "session_id", sessionId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,7 +235,12 @@ func (w *Worker) handleProxy(listenerCfg *listenerutil.ListenerConfig) (http.Han
|
||||
}
|
||||
return
|
||||
}
|
||||
defer session.CloseConnections(ctx, sessClient, w.sessionInfoMap, map[string]string{ci.Id: si.Id})
|
||||
event.WriteSysEvent(ctx, op, "connection successfully authorized", "session_id", sessionId, "connection_id", ci.Id)
|
||||
defer func() {
|
||||
if session.CloseConnections(ctx, sessClient, w.sessionInfoMap, map[string]string{ci.Id: si.Id}) {
|
||||
event.WriteSysEvent(ctx, op, "connection closed", "session_id", sessionId, "connection_id", ci.Id)
|
||||
}
|
||||
}()
|
||||
|
||||
si.Lock()
|
||||
ci.ConnCtx = connCtx
|
||||
|
||||
@@ -112,19 +112,20 @@ func closeConnection(ctx context.Context, sessClient pbs.SessionServiceClient, r
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// CloseConnections is a helper worker function that sends connection
|
||||
// close requests to the controller, and sets close times within the
|
||||
// worker. It is called during the worker status loop and on
|
||||
// connection exit on the proxy.
|
||||
// CloseConnections is a helper worker function that sends connection close
|
||||
// requests to the controller, and sets close times within the worker. It is
|
||||
// called during the worker status loop and on connection exit on the proxy.
|
||||
//
|
||||
// closeInfo is a map of connections mapped to their individual
|
||||
// session.
|
||||
func CloseConnections(ctx context.Context, sessClient pbs.SessionServiceClient, sessionInfo *sync.Map, closeInfo map[string]string) {
|
||||
// The boolean indicates whether the function was successful, e.g. had any
|
||||
// errors. Individual events will be sent for the errors if there are any.
|
||||
//
|
||||
// closeInfo is a map of connections mapped to their individual session.
|
||||
func CloseConnections(ctx context.Context, sessClient pbs.SessionServiceClient, sessionInfo *sync.Map, closeInfo map[string]string) bool {
|
||||
const op = "session.CloseConnections"
|
||||
if closeInfo == nil {
|
||||
// This should not happen, but it's a no-op if it does. Just
|
||||
// return.
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
// How we handle close info depends on whether or not we succeeded with
|
||||
@@ -155,7 +156,7 @@ func CloseConnections(ctx context.Context, sessClient pbs.SessionServiceClient,
|
||||
|
||||
if err != nil {
|
||||
event.WriteError(ctx, op, err, event.WithInfoMsg("serious error in processing return data from controller, aborting additional session/connection state modification"))
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
// Mark connections as closed
|
||||
@@ -164,7 +165,10 @@ func CloseConnections(ctx context.Context, sessClient pbs.SessionServiceClient,
|
||||
for _, err := range errs {
|
||||
event.WriteError(ctx, op, err, event.WithInfoMsg("error marking connection closed in state"))
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// makeCloseConnectionRequest creates a CloseConnectionRequest for
|
||||
|
||||
@@ -322,7 +322,7 @@ func (w *Worker) cleanupConnections(cancelCtx context.Context, ignoreSessionStat
|
||||
if err != nil {
|
||||
event.WriteError(cancelCtx, op, err, event.WithInfo("failed to create controller session client, connections won't be cleaned up"))
|
||||
} else {
|
||||
session.CloseConnections(cancelCtx, sessClient, w.sessionInfoMap, closeInfo)
|
||||
_ = session.CloseConnections(cancelCtx, sessClient, w.sessionInfoMap, closeInfo)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user