Files
Roberto Bruggemann 710d665c41 Upgrade k8s.io/client-go to kubernetes-1.9.1
Upgraded from 99c19923, branch release-3.0.

This required fetching or upgrading the following:
* k8s.io/api to kubernetes-1.9.1
* k8s.io/apimachinery to kubernetes-1.9.1
* github.com/juju/ratelimit to 1.0.1
* github.com/spf13/pflag to 4c012f6d

Also, update Scope's imports/function calls to be compatible with the new client.
2018-01-30 10:14:42 +00:00

61 lines
897 B
Go

package appstats
import (
"reflect"
"github.com/golang/protobuf/proto"
)
const (
cost_Write = 10
cost_Read = 7
cost_Small = 1
)
// todo: implement read and small ops costs
func getCost(p proto.Message) int64 {
v := reflect.ValueOf(p)
v = reflect.Indirect(v)
if v.Kind() != reflect.Struct {
return 0
}
var cost int64
cost += extractCost(v)
return cost
}
func extractCost(v reflect.Value) int64 {
v = v.FieldByName("Cost")
if v.Kind() != reflect.Ptr {
return 0
}
v = v.Elem()
if v.Kind() != reflect.Struct {
return 0
}
var cost int64
extract := func(name string) int64 {
w := v.FieldByName(name)
if w.Kind() != reflect.Ptr {
return 0
}
w = w.Elem()
switch w.Kind() {
case reflect.Int, reflect.Int32, reflect.Int64:
return w.Int()
}
return 0
}
cost += extract("IndexWrites")
cost += extract("EntityWrites")
return cost * cost_Write
}