Skip to content

Commit

Permalink
acl: Pass request ctx to acl.GetLog function
Browse files Browse the repository at this point in the history
Passing the request ctx to the GetLog function allows to stop the syslog stream (in case of OVN being deployed with MicroOVN)
in case of request interruption

Signed-off-by: Gabriel Mougard <[email protected]>
  • Loading branch information
gabrielmougard committed Dec 3, 2024
1 parent 62f251d commit 3990d6f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lxd/network/acl/acl_interface.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package acl

import (
"context"

"github.com/canonical/lxd/lxd/cluster/request"
"github.com/canonical/lxd/lxd/state"
"github.com/canonical/lxd/shared/api"
Expand All @@ -19,7 +21,7 @@ type NetworkACL interface {
UsedBy() ([]string, error)

// GetLog.
GetLog(clientType request.ClientType) (string, error)
GetLog(ctx context.Context, clientType request.ClientType) (string, error)

// Internal validation.
validateName(name string) error
Expand Down
4 changes: 2 additions & 2 deletions lxd/network/acl/driver_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ func (d *common) Delete() error {
}

// GetLog gets the ACL log.
func (d *common) GetLog(clientType request.ClientType) (string, error) {
func (d *common) GetLog(ctx context.Context, clientType request.ClientType) (string, error) {
// ACLs aren't specific to a particular network type but the log only works with OVN.
var logEntries []string
var err error
Expand All @@ -759,7 +759,7 @@ func (d *common) GetLog(clientType request.ClientType) (string, error) {
targetPath, err := os.Readlink("/run/openvswitch")
if err == nil && strings.HasSuffix(targetPath, "/microovn/chassis/switch") {
prefix := fmt.Sprintf("lxd_acl%d-", d.id)
logEntries, err = ovnParseLogEntriesFromJournald(context.TODO(), "snap.microovn.chassis.service", prefix)
logEntries, err = ovnParseLogEntriesFromJournald(ctx, "snap.microovn.chassis.service", prefix)
if err != nil {
return "", fmt.Errorf("Failed to get OVN log entries from syslog: %v\n", err)
}
Expand Down
2 changes: 1 addition & 1 deletion lxd/network_acls.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ func networkACLLogGet(d *Daemon, r *http.Request) response.Response {
}

clientType := clusterRequest.UserAgentClientType(r.Header.Get("User-Agent"))
log, err := netACL.GetLog(clientType)
log, err := netACL.GetLog(r.Context(), clientType)
if err != nil {
return response.SmartError(err)
}
Expand Down

0 comments on commit 3990d6f

Please sign in to comment.