Skip to content

Commit

Permalink
lxd: Update MetricsCallback usage
Browse files Browse the repository at this point in the history
Signed-off-by: hamistao <[email protected]>
  • Loading branch information
hamistao committed Sep 11, 2024
1 parent ad6a2ba commit bd8abf5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lxd/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (r *eventsServe) Render(w http.ResponseWriter, req *http.Request) error {

if err == nil {
// If there was an error on Render, the callback function will be called during the error handling.
request.MetricsCallback(req, metrics.Success)
metrics.UseMetricsCallback(req, metrics.Success)
}

return err
Expand Down
2 changes: 1 addition & 1 deletion lxd/instance_sftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (r *sftpServeResponse) Render(w http.ResponseWriter, req *http.Request) err

wg.Wait() // Wait for copy go routine to finish.

request.MetricsCallback(req, metrics.Success)
metrics.UseMetricsCallback(req, metrics.Success)

return nil
}
7 changes: 3 additions & 4 deletions lxd/operations/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net/http"

"github.com/canonical/lxd/lxd/metrics"
"github.com/canonical/lxd/lxd/request"
"github.com/canonical/lxd/lxd/response"
"github.com/canonical/lxd/lxd/util"
"github.com/canonical/lxd/shared/api"
Expand All @@ -31,9 +30,9 @@ func (r *operationResponse) Render(w http.ResponseWriter, req *http.Request) err
r.op.SetOnDone(func(op *Operation) {
sc := op.Status()
if sc == api.Success || sc == api.Cancelled {
request.MetricsCallback(req, metrics.Success)
metrics.UseMetricsCallback(req, metrics.Success)
} else {
request.MetricsCallback(req, metrics.ErrorServer)
metrics.UseMetricsCallback(req, metrics.ErrorServer)
}
})

Expand Down Expand Up @@ -123,7 +122,7 @@ func (r *forwardedOperationResponse) Render(w http.ResponseWriter, req *http.Req

if err == nil {
// If there was an error on Render, the callback function will be called during the error handling.
request.MetricsCallback(req, metrics.Success)
metrics.UseMetricsCallback(req, metrics.Success)
}

return err
Expand Down
5 changes: 2 additions & 3 deletions lxd/operations/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/gorilla/websocket"

"github.com/canonical/lxd/lxd/metrics"
"github.com/canonical/lxd/lxd/request"
"github.com/canonical/lxd/lxd/response"
"github.com/canonical/lxd/shared/ws"
)
Expand All @@ -32,7 +31,7 @@ func (r *operationWebSocket) Render(w http.ResponseWriter, req *http.Request) er

if err == nil {
// If there was an error on Render, the callback function will be called during the error handling.
request.MetricsCallback(req, metrics.Success)
metrics.UseMetricsCallback(req, metrics.Success)
}

return err
Expand Down Expand Up @@ -73,7 +72,7 @@ func (r *forwardedOperationWebSocket) Render(w http.ResponseWriter, req *http.Re
_ = target.Close()

// If there was an error on Render, the callback function will be called during the error handling.
request.MetricsCallback(req, metrics.Success)
metrics.UseMetricsCallback(req, metrics.Success)

return nil
}
Expand Down
13 changes: 6 additions & 7 deletions lxd/response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"github.com/canonical/lxd/client"
"github.com/canonical/lxd/lxd/metrics"
"github.com/canonical/lxd/lxd/request"
"github.com/canonical/lxd/lxd/ucred"
"github.com/canonical/lxd/lxd/util"
"github.com/canonical/lxd/shared/api"
Expand Down Expand Up @@ -210,9 +209,9 @@ func (r *syncResponse) Render(w http.ResponseWriter, req *http.Request) (err err
// If there was an error on Render, the callback function will be called during the error handling.
if err == nil {
if r.success {
request.MetricsCallback(req, metrics.Success)
metrics.UseMetricsCallback(req, metrics.Success)
} else {
request.MetricsCallback(req, metrics.ErrorServer)
metrics.UseMetricsCallback(req, metrics.ErrorServer)
}
}
}()
Expand Down Expand Up @@ -368,10 +367,10 @@ func (r *errorResponse) Render(w http.ResponseWriter, req *http.Request) error {
// Use the callback function to count the request for the API metrics.
if r.code >= 400 && r.code < 500 {
// 4* codes are considered client errors on HTTP.
request.MetricsCallback(req, metrics.ErrorClient)
metrics.UseMetricsCallback(req, metrics.ErrorClient)
} else {
// Any other status code here shoud be higher than or equal to 500 and is considered a server error.
request.MetricsCallback(req, metrics.ErrorServer)
metrics.UseMetricsCallback(req, metrics.ErrorServer)
}
}()

Expand Down Expand Up @@ -437,7 +436,7 @@ func (r *fileResponse) Render(w http.ResponseWriter, req *http.Request) (err err
defer func() {
if err == nil {
// If there was an error on Render, the callback function will be called during the error handling.
request.MetricsCallback(req, metrics.Success)
metrics.UseMetricsCallback(req, metrics.Success)
}
}()

Expand Down Expand Up @@ -617,7 +616,7 @@ func (r *manualResponse) Render(w http.ResponseWriter, req *http.Request) error

if err == nil {
// If there was an error on Render, the callback function will be called during the error handling.
request.MetricsCallback(req, metrics.Success)
metrics.UseMetricsCallback(req, metrics.Success)
}

return err
Expand Down

0 comments on commit bd8abf5

Please sign in to comment.