Upgrade dependent version: github.com/open-policy-agent/opa (#5315)

Upgrade dependent version: github.com/open-policy-agent/opa v0.18.0 -> v0.45.0

Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io>

Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io>
This commit is contained in:
hongzhouzi
2022-10-31 10:58:55 +08:00
committed by GitHub
parent 668fca1773
commit ef03b1e3df
363 changed files with 277341 additions and 13544 deletions

View File

@@ -19,8 +19,10 @@ import (
// Well-known metric names.
const (
BundleRequest = "bundle_request"
ServerHandler = "server_handler"
ServerQueryCacheHit = "server_query_cache_hit"
SDKDecisionEval = "sdk_decision_eval"
RegoQueryCompile = "rego_query_compile"
RegoQueryEval = "rego_query_eval"
RegoQueryParse = "rego_query_parse"
@@ -31,6 +33,7 @@ const (
RegoInputParse = "rego_input_parse"
RegoLoadFiles = "rego_load_files"
RegoLoadBundles = "rego_load_bundles"
RegoExternalResolve = "rego_external_resolve"
)
// Info contains attributes describing the underlying metrics provider.
@@ -50,6 +53,10 @@ type Metrics interface {
json.Marshaler
}
type TimerMetrics interface {
Timers() map[string]interface{}
}
type metrics struct {
mtx sync.Mutex
timers map[string]Timer
@@ -69,7 +76,7 @@ type metric struct {
Value interface{}
}
func (m *metrics) Info() Info {
func (*metrics) Info() Info {
return Info{
Name: "<built-in>",
}
@@ -153,6 +160,16 @@ func (m *metrics) All() map[string]interface{} {
return result
}
func (m *metrics) Timers() map[string]interface{} {
m.mtx.Lock()
defer m.mtx.Unlock()
ts := map[string]interface{}{}
for n, t := range m.timers {
ts[m.formatKey(n, t)] = t.Value()
}
return ts
}
func (m *metrics) Clear() {
m.mtx.Lock()
defer m.mtx.Unlock()
@@ -198,7 +215,7 @@ func (t *timer) Start() {
func (t *timer) Stop() int64 {
t.mtx.Lock()
defer t.mtx.Unlock()
delta := time.Now().Sub(t.start).Nanoseconds()
delta := time.Since(t.start).Nanoseconds()
t.value += delta
return delta
}
@@ -267,6 +284,7 @@ func (h *histogram) Value() interface{} {
type Counter interface {
Value() interface{}
Incr()
Add(n uint64)
}
type counter struct {
@@ -277,6 +295,18 @@ func (c *counter) Incr() {
atomic.AddUint64(&c.c, 1)
}
func (c *counter) Add(n uint64) {
atomic.AddUint64(&c.c, n)
}
func (c *counter) Value() interface{} {
return atomic.LoadUint64(&c.c)
}
func Statistics(num ...int64) interface{} {
t := newHistogram()
for _, n := range num {
t.Update(n)
}
return t.Value()
}