-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extcache: Add experiment for extcache
- Loading branch information
1 parent
2ac2665
commit af79802
Showing
4 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package experiment | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
const percentBase = uint64(10000) | ||
|
||
type Percent struct { | ||
threshold uint64 | ||
} | ||
|
||
func (p *Percent) UnmarshalJSON(b []byte) error { | ||
var pct float64 | ||
if err := json.Unmarshal(b, &pct); err != nil { | ||
return err | ||
} | ||
if pct < 0 { | ||
return fmt.Errorf("percent is negative: %v", pct) | ||
} | ||
p.threshold = uint64(pct * float64(percentBase) / 100) | ||
return nil | ||
} | ||
|
||
type OptIn struct { | ||
OptIn Percent | ||
} | ||
|
||
func (o *OptIn) Enabled(val uint64) bool { | ||
return val%percentBase < o.OptIn.threshold | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters