Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apis/server/image_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ func (s *Server) removeImage(ctx context.Context, rw http.ResponseWriter, req *h

label := util_metrics.ActionDeleteLabel
defer func(start time.Time) {
metrics.ImageActionsCounter.WithLabelValues(label).Inc()
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we could judge the return err here to decide how to handle the counter? if err was not found, not add it?

Copy link
Contributor

Choose a reason for hiding this comment

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

it's more clear I think

metrics.ImageActionsTimer.WithLabelValues(label).Observe(time.Since(start).Seconds())
}(time.Now())

Expand All @@ -153,10 +152,12 @@ func (s *Server) removeImage(ctx context.Context, rw http.ResponseWriter, req *h
}

if err := s.ImageMgr.RemoveImage(ctx, name, isForce); err != nil {
metrics.ImageActionsCounter.WithLabelValues(label).Inc()
return err
}

metrics.ImageSuccessActionsCounter.WithLabelValues(label).Inc()
metrics.ImageActionsCounter.WithLabelValues(label).Inc()
rw.WriteHeader(http.StatusNoContent)
return nil
}
Expand Down
11 changes: 9 additions & 2 deletions test/api_image_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,25 @@ func (suite *APIImageMetricsSuite) checkAction(c *check.C, label string) {
countBefore, countSuccessBefore := GetMetric(c,
key,
keySuccess)
countAdd := 0
switch label {
case "pull":
PullImage(c, helloworldImage)
countAdd = 1
case "delete":
resp, err := request.Delete("/images/" + helloworldImage)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 204)
countAdd = 1
case "delete_nonImage":
_, err := request.Delete("/images/" + "nonImage")
c.Assert(err, check.NotNil)
countAdd = 0
}

count, successCount := GetMetric(c,
key,
keySuccess)
c.Assert(count, check.Equals, countBefore+1)
c.Assert(successCount, check.Equals, countSuccessBefore+1)
c.Assert(count, check.Equals, countBefore+countAdd)
c.Assert(successCount, check.Equals, countSuccessBefore+countAdd)
}