Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(553)

Unified Diff: go/src/infra/gae/libs/gae/filters/count/count.go

Issue 1239103003: Add "filters/count" filter. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@add_filters
Patch Set: more better now Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | go/src/infra/gae/libs/gae/filters/count/count.infra_testing » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/gae/libs/gae/filters/count/count.go
diff --git a/go/src/infra/gae/libs/gae/filters/count/count.go b/go/src/infra/gae/libs/gae/filters/count/count.go
new file mode 100644
index 0000000000000000000000000000000000000000..a5478868128be9bcbb3d29e476ffe816e4f14bf6
--- /dev/null
+++ b/go/src/infra/gae/libs/gae/filters/count/count.go
@@ -0,0 +1,37 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Package count contains 'counter' filters for all the gae services. This
+// serves as a set of simple example filters, and also enables other filters
+// to test to see if certain underlying APIs are called when they should be
+// (e.g. for the datastore mcache filter, for example).
+package count
+
+import (
+ "sync/atomic"
+)
+
+// Entry is a success/fail pair for a single API method. It's returned
+// by the Counter interface.
+type Entry struct {
+ Successes int64
+ Errors int64
+}
+
+// Total is a convenience function for getting the total number of calls to
+// this API. It's Successes+Errors.
+func (e Entry) Total() int64 { return e.Successes + e.Errors }
+
+func (e *Entry) up(errs ...error) error {
nodir 2015/09/19 05:45:50 why do you accept a slice but you use only first e
+ err := error(nil)
+ if len(errs) > 0 {
+ err = errs[0]
+ }
+ if err == nil {
+ atomic.AddInt64(&e.Successes, 1)
+ } else {
+ atomic.AddInt64(&e.Errors, 1)
+ }
+ return err
+}
« no previous file with comments | « no previous file | go/src/infra/gae/libs/gae/filters/count/count.infra_testing » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698