mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 18:53:35 +00:00
vendor update for E2E framework
Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Gopkg.lockGopkg.tomlpicker_wrapper.gopreloader.gowell_known_annotations.gowell_known_annotations_windows.gowell_known_labels.go
vendor
github.com
PuerkitoBio
beorn7
docker
distribution
spdystream
emicklei
go-restful
LICENSEcompress.gocompressor_cache.gocompressor_pools.gocompressors.goconstants.gocontainer.gocors_filter.gocurly.gocurly_route.godoc.goentity_accessors.gofilter.gojson.gojsoniter.gojsr311.go
log
logger.gomime.gooptions_filter.goparameter.gopath_expression.gopath_processor.gorequest.goresponse.goroute.goroute_builder.gorouter.goservice_error.goweb_service.goweb_service_container.goevanphx
fatih
camelcase
ghodss
go-openapi
jsonpointer
jsonreference
spec
LICENSEbindata.gocache.gocontact_info.godebug.goexpander.goexternal_docs.goheader.goinfo.goitems.golicense.gonormalizer.gooperation.goparameter.gopath_item.gopaths.goref.goresponse.goresponses.goschema.goschema_loader.gosecurity_scheme.gospec.goswagger.gotag.gounused.goxml_object.go
swag
gogo
protobuf
gogoproto
protoc-gen-gogo
golang
google
gregjones
httpcache
hashicorp
hpcloud
tail
inconshreveable
mailru
easyjson
matttproud
onsi
ginkgo
LICENSE
config
ginkgo_dsl.gointernal
codelocation
containernode
failer
leafnodes
benchmarker.gointerfaces.goit_node.gomeasure_node.gorunner.gosetup_nodes.gosuite_nodes.gosynchronized_after_suite_node.gosynchronized_before_suite_node.go
remote
aggregator.goforwarding_reporter.gooutput_interceptor.gooutput_interceptor_unix.gooutput_interceptor_win.goserver.gosyscall_dup_linux_arm64.gosyscall_dup_solaris.gosyscall_dup_unix.go
spec
spec_iterator
index_computer.goparallel_spec_iterator.goserial_spec_iterator.gosharded_parallel_spec_iterator.gospec_iterator.go
specrunner
suite
testingtproxy
writer
reporters
default_reporter.gofake_reporter.gojunit_reporter.goreporter.go
stenographer
teamcity_reporter.gotypes
gomega
LICENSEmatchers.go
format
gomega_dsl.gointernal
assertion
asyncassertion
oraclematcher
testingtsupport
matchers
and.goassignable_to_type_of_matcher.goattributes_slice.gobe_a_directory.gobe_a_regular_file.gobe_an_existing_file.gobe_closed_matcher.gobe_empty_matcher.gobe_equivalent_to_matcher.gobe_false_matcher.gobe_identical_to.gobe_nil_matcher.gobe_numerically_matcher.gobe_sent_matcher.gobe_temporally_matcher.gobe_true_matcher.gobe_zero_matcher.goconsist_of.gocontain_element_matcher.gocontain_substring_matcher.goequal_matcher.gohave_cap_matcher.gohave_key_matcher.gohave_key_with_value_matcher.gohave_len_matcher.gohave_occurred_matcher.gohave_prefix_matcher.gohave_suffix_matcher.gomatch_error_matcher.gomatch_json_matcher.gomatch_regexp_matcher.gomatch_xml_matcher.gomatch_yaml_matcher.gonot.goor.gopanic_matcher.goreceive_matcher.gosemi_structured_data_support.gosucceed_matcher.gotype_support.gowith_transform.go
support
goraph
types
opencontainers
petar
peterbourgon
pmezard
go-difflib
prometheus
client_golang
client_model
common
procfs
spf13
cobra
stretchr
golang.org
x
crypto
curve25519
const_amd64.hconst_amd64.scswap_amd64.scurve25519.godoc.gofreeze_amd64.sladderstep_amd64.smont25519_amd64.gomul_amd64.ssquare_amd64.s
ed25519
internal
chacha20
asm_arm64.sasm_ppc64le.schacha_arm64.gochacha_generic.gochacha_noasm.gochacha_ppc64le.gochacha_s390x.gochacha_s390x.sxor.go
subtle
pbkdf2
poly1305
mac_noasm.gopoly1305.gosum_amd64.gosum_amd64.ssum_arm.gosum_arm.ssum_generic.gosum_noasm.gosum_s390x.gosum_s390x.ssum_vmsl_s390x.s
ssh
net
html
http2
idna
websocket
oauth2
sys
cpu
asm_aix_ppc64.sbyteorder.gocpu.gocpu_aix_ppc64.gocpu_arm.gocpu_gc_s390x.gocpu_gc_x86.gocpu_gccgo.ccpu_gccgo.gocpu_gccgo_s390x.gocpu_linux.gocpu_linux_arm64.gocpu_linux_ppc64x.gocpu_linux_s390x.gocpu_mips64x.gocpu_mipsx.gocpu_other_arm64.gocpu_s390x.scpu_wasm.gocpu_x86.gocpu_x86.ssyscall_aix_ppc64_gc.go
unix
asm_linux_riscv64.sasm_openbsd_arm64.smkpost.gomksyscall.gomksyscall_aix_ppc.gomksyscall_aix_ppc64.gomksysctl_openbsd.gopledge_openbsd.gosockcmsg_unix.gosyscall.gosyscall_aix.gosyscall_aix_ppc.gosyscall_aix_ppc64.gosyscall_freebsd.gosyscall_linux.gosyscall_linux_arm.gosyscall_openbsd_arm64.gosyscall_unix.gotypes_aix.gounveil_openbsd.gozerrors_aix_ppc.gozerrors_aix_ppc64.gozerrors_linux_386.gozerrors_linux_amd64.gozerrors_linux_arm.gozerrors_linux_arm64.gozerrors_linux_mips.gozerrors_linux_mips64.gozerrors_linux_mips64le.gozerrors_linux_mipsle.gozerrors_linux_ppc64.gozerrors_linux_ppc64le.gozerrors_linux_riscv64.gozerrors_linux_s390x.gozerrors_linux_sparc64.gozerrors_openbsd_arm64.gozsyscall_aix_ppc.gozsyscall_aix_ppc64.gozsyscall_aix_ppc64_gc.gozsyscall_aix_ppc64_gccgo.gozsyscall_linux_386.gozsyscall_linux_amd64.gozsyscall_linux_arm.gozsyscall_linux_arm64.gozsyscall_linux_mips.gozsyscall_linux_mips64.gozsyscall_linux_mips64le.gozsyscall_linux_mipsle.gozsyscall_linux_ppc64.gozsyscall_linux_ppc64le.gozsyscall_linux_riscv64.gozsyscall_linux_s390x.gozsyscall_linux_sparc64.gozsyscall_openbsd_arm64.gozsysctl_openbsd_386.gozsysctl_openbsd_amd64.gozsysctl_openbsd_arm.gozsysctl_openbsd_arm64.gozsysnum_linux_386.gozsysnum_linux_amd64.gozsysnum_linux_arm.gozsysnum_linux_arm64.gozsysnum_linux_mips.gozsysnum_linux_mips64.gozsysnum_linux_mips64le.gozsysnum_linux_mipsle.gozsysnum_linux_ppc64.gozsysnum_linux_ppc64le.gozsysnum_linux_riscv64.gozsysnum_linux_s390x.gozsysnum_linux_sparc64.gozsysnum_openbsd_arm64.goztypes_aix_ppc.goztypes_aix_ppc64.goztypes_darwin_386.goztypes_darwin_amd64.goztypes_darwin_arm.goztypes_darwin_arm64.goztypes_dragonfly_amd64.goztypes_freebsd_386.goztypes_freebsd_amd64.goztypes_freebsd_arm.goztypes_freebsd_arm64.goztypes_linux_386.goztypes_linux_amd64.goztypes_linux_arm.goztypes_linux_arm64.goztypes_linux_mips.goztypes_linux_mips64.goztypes_linux_mips64le.goztypes_linux_mipsle.goztypes_linux_ppc64.goztypes_linux_ppc64le.goztypes_linux_riscv64.goztypes_linux_s390x.goztypes_linux_sparc64.goztypes_netbsd_386.goztypes_netbsd_amd64.goztypes_netbsd_arm.goztypes_netbsd_arm64.goztypes_openbsd_arm64.go
windows
text
collate
encoding
internal
colltab
gen
language
common.gocompact.go
compact
compose.gocoverage.gogen.gogen_common.golanguage.golookup.gomatch.goparse.gotables.gotags.gotriegen
ucd
utf8internal
language
runes
transform
unicode
bidi
cldr
norm
composition.goforminfo.goiter.gomaketables.gonormalize.goreadwriter.gotables10.0.0.gotables11.0.0.gotables9.0.0.gotransform.go
rangetable
width
google.golang.org
genproto
googleapis
rpc
status
grpc
balancer
balancer_conn_wrappers.gobalancer_v1_wrapper.goclientconn.gocodes
credentials
dialoptions.goencoding
grpclog
internal
balancerload
channelz
envconfig
syscall
transport
resolver
resolver_conn_wrapper.gorpc_util.goserver.goservice_config.gostats
stream.gotrace.goversion.gogopkg.in
fsnotify.v1
AUTHORSLICENSEfen.gofsnotify.goinotify.goinotify_poller.gokqueue.goopen_mode_bsd.goopen_mode_darwin.gowindows.go
square
go-jose.v2
tomb.v1
k8s.io
api
admission
v1beta1
imagepolicy
apiextensions-apiserver
apimachinery
pkg
api
apis
meta
internalversion
v1
util
cache
diff
duration
httpstream
mergepatch
rand
remotecommand
strategicpatch
uuid
version
third_party
apiserver
LICENSE
pkg
apis
audit
doc.gohelpers.goregister.gotypes.go
v1
doc.gogenerated.pb.goregister.gotypes.gozz_generated.conversion.gozz_generated.deepcopy.gozz_generated.defaults.go
v1alpha1
conversion.godoc.gogenerated.pb.goregister.gotypes.gozz_generated.conversion.gozz_generated.deepcopy.gozz_generated.defaults.go
v1beta1
conversion.godoc.gogenerated.pb.goregister.gotypes.gozz_generated.conversion.gozz_generated.deepcopy.gozz_generated.defaults.go
zz_generated.deepcopy.goaudit
authentication
authorization
authorizer
features
storage
util
feature
cli-runtime
LICENSE
pkg
genericclioptions
builder_flags.gobuilder_flags_fake.goconfig_flags.goconfig_flags_fake.godoc.gofilename_flags.goio_options.gojson_yaml_flags.gojsonpath_flags.gokube_template_flags.goname_flags.goprint_flags.gorecord_flags.gotemplate_flags.go
kustomize
printers
resource
client-go
discovery
cached
dynamic
informers
admissionregistration
apps
auditregistration
autoscaling
batch
certificates
coordination
core
events
extensions
factory.gogeneric.gointernalinterfaces
networking
node
policy
rbac
scheduling
settings
storage
listers
admissionregistration
apps
v1
controllerrevision.godaemonset.godaemonset_expansion.godeployment.godeployment_expansion.goexpansion_generated.goreplicaset.goreplicaset_expansion.gostatefulset.gostatefulset_expansion.go
v1beta1
v1beta2
auditregistration
autoscaling
v1
v2beta1
v2beta2
batch
v1
v1beta1
v2alpha1
certificates
coordination
core
v1
componentstatus.goconfigmap.goendpoints.goevent.goexpansion_generated.golimitrange.gonamespace.gonode.gonode_expansion.gopersistentvolume.gopersistentvolumeclaim.gopod.gopodtemplate.goreplicationcontroller.goreplicationcontroller_expansion.goresourcequota.gosecret.goservice.goservice_expansion.goserviceaccount.go
events
extensions
v1beta1
networking
node
policy
v1beta1
rbac
v1
v1alpha1
v1beta1
scheduling
v1
v1alpha1
v1beta1
settings
storage
restmapper
scale
client.godoc.gointerfaces.goutil.go
scheme
appsint
appsv1beta1
appsv1beta2
autoscalingv1
doc.goextensionsint
extensionsv1beta1
register.gotypes.gozz_generated.deepcopy.gothird_party
tools
cache
controller.godelta_fifo.godoc.goexpiration_cache.goexpiration_cache_fakes.gofake_custom_store.gofifo.goheap.goindex.golisters.golistwatch.gomutation_cache.gomutation_detector.goreflector.goreflector_metrics.goshared_informer.gostore.gothread_safe_store.goundelta_store.go
pager
record
remotecommand
watch
transport
spdy
util
cloud-provider
cluster-bootstrap
component-base
csi-translation-lib
klog
kube-aggregator
kube-openapi
kubernetes
cmd
kubeadm
pkg
api
apis
admissionregistration
apps
auditregistration
authentication
authorization
autoscaling
batch
certificates
coordination
core
annotation_key_constants.godoc.gofield_constants.go
helper
install
json.goobjectreference.gopods
register.goresource.gotaint.gotoleration.gotypes.gov1
validation
zz_generated.deepcopy.goevents
extensions
networking
node
policy
rbac
doc.gohelpers.go
install
register.gotypes.gov1
defaults.godoc.goevaluation_helpers.gohelpers.goregister.gozz_generated.conversion.gozz_generated.deepcopy.gozz_generated.defaults.go
v1alpha1
conversion.godefaults.godoc.gohelpers.goregister.gozz_generated.conversion.gozz_generated.defaults.go
v1beta1
zz_generated.deepcopy.goscheduling
settings
storage
capabilities
client
clientset_generated
internalclientset
clientset.godoc.go
scheme
typed
admissionregistration
internalversion
apps
internalversion
auditregistration
authentication
internalversion
authorization
internalversion
autoscaling
batch
internalversion
certificates
internalversion
coordination
internalversion
core
internalversion
componentstatus.goconfigmap.gocore_client.godoc.goendpoints.goevent.goevent_expansion.gogenerated_expansion.golimitrange.gonamespace.gonamespace_expansion.gonode.gonode_expansion.gopersistentvolume.gopersistentvolumeclaim.gopod.gopod_expansion.gopodtemplate.goreplicationcontroller.goresourcequota.gosecret.goservice.goservice_expansion.goserviceaccount.go
events
internalversion
extensions
internalversion
networking
node
internalversion
policy
internalversion
rbac
internalversion
scheduling
settings
internalversion
storage
conditions
controller
client_builder.gocontroller_ref_manager.gocontroller_utils.go
deployment
doc.gojob
lookup_cache.gonodelifecycle
service
util
volume
features
fieldpath
kubectl
apply.go
apps
conditions.godescribe
doc.gohistory.gointerfaces.gorollback.gorolling_updater.gorollout_status.goscale.goscheme
util
certificate
deployment
event
fieldpath
pod_port.gopodutils
qos
rbac
resource
service_port.goslice
storage
umask.goumask_windows.goutil.gokubelet
apis
config
cri
runtime
v1alpha2
stats
v1alpha1
container
cache.gocontainer_gc.gocontainer_reference_manager.gohelpers.goos.goref.goresize.goruntime.goruntime_cache.goruntime_cache_fake.gosync_result.go
dockershim
metrics
events
lifecycle
metrics
sysctl
types
util
format
master
proxy
registry
core
service
scheduler
security
apparmor
podsecuritypolicy
serviceaccount
ssh
util
goroutinemap
hash
labels
metrics
node
parsers
resizefs
system
taints
version
volume
doc.gometrics_cached.gometrics_du.gometrics_errors.gometrics_nil.gometrics_statfs.gonoop_expandable_plugin.goplugins.go
util
atomic_writer.goattach_limit.godevice_util.godevice_util_linux.godevice_util_unsupported.godoc.gofinalizer.go
volume.govolume_linux.govolume_unsupported.gofs
io_util.gometrics.gonested_volumes.gorecyclerclient
resize_util.gosubpath
types
util.govolumepathhandler
test
e2e
framework
authorizer_util.gocleanup.gocreate.godeployment_util.goexec_util.goflake_reporting_util.goframework.goget-kubemark-resource-usage.go
ginkgowrapper
google_compute.gogpu_util.gojobs_util.gokubelet_stats.golog_size_monitoring.gometrics
api_server_metrics.gocluster_autoscaler_metrics.gocontroller_manager_metrics.gogeneric_metrics.gokubelet_metrics.gometrics_grabber.goscheduler_metrics.go
metrics_util.gonetworking_utils.gonodes_util.goperf_util.gopods.goprofile_gatherer.goprovider.gopsp_util.gopv_util.gorc_util.goresource_usage_gatherer.gors_util.goservice_util.gosize.gossh.gostatefulset_utils.gotest_context.gotestfiles
upgrade_util.goutil.govolume_util.gomanifest
perftype
utils
third_party
forked
golang
expansion
utils
buffer
io
net
pointer
strings
trace
sigs.k8s.io
kustomize
LICENSEimage.golabelsandannotations.gomultitransformer.gomutatefield.gonamereference.gonamespace.gonooptransformer.goprefixsuffixname.gorefvars.gotransformer.go
pkg
commands
build
constants
expansion
factory
fs
git
gvk
ifc
image
internal
error
loader
patch
resid
resmap
resource
target
transformers
config
defaultconfig
commonannotations.gocommonlabels.godefaultconfig.gonameprefix.gonamereference.gonamespace.govarreference.go
factory.gofactorycrd.gofieldspec.gonamebackreferences.gotransformerconfig.gotypes
416
vendor/github.com/prometheus/common/model/value.go
generated
vendored
Normal file
416
vendor/github.com/prometheus/common/model/value.go
generated
vendored
Normal file
@ -0,0 +1,416 @@
|
||||
// Copyright 2013 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
// ZeroSamplePair is the pseudo zero-value of SamplePair used to signal a
|
||||
// non-existing sample pair. It is a SamplePair with timestamp Earliest and
|
||||
// value 0.0. Note that the natural zero value of SamplePair has a timestamp
|
||||
// of 0, which is possible to appear in a real SamplePair and thus not
|
||||
// suitable to signal a non-existing SamplePair.
|
||||
ZeroSamplePair = SamplePair{Timestamp: Earliest}
|
||||
|
||||
// ZeroSample is the pseudo zero-value of Sample used to signal a
|
||||
// non-existing sample. It is a Sample with timestamp Earliest, value 0.0,
|
||||
// and metric nil. Note that the natural zero value of Sample has a timestamp
|
||||
// of 0, which is possible to appear in a real Sample and thus not suitable
|
||||
// to signal a non-existing Sample.
|
||||
ZeroSample = Sample{Timestamp: Earliest}
|
||||
)
|
||||
|
||||
// A SampleValue is a representation of a value for a given sample at a given
|
||||
// time.
|
||||
type SampleValue float64
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (v SampleValue) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(v.String())
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (v *SampleValue) UnmarshalJSON(b []byte) error {
|
||||
if len(b) < 2 || b[0] != '"' || b[len(b)-1] != '"' {
|
||||
return fmt.Errorf("sample value must be a quoted string")
|
||||
}
|
||||
f, err := strconv.ParseFloat(string(b[1:len(b)-1]), 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*v = SampleValue(f)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Equal returns true if the value of v and o is equal or if both are NaN. Note
|
||||
// that v==o is false if both are NaN. If you want the conventional float
|
||||
// behavior, use == to compare two SampleValues.
|
||||
func (v SampleValue) Equal(o SampleValue) bool {
|
||||
if v == o {
|
||||
return true
|
||||
}
|
||||
return math.IsNaN(float64(v)) && math.IsNaN(float64(o))
|
||||
}
|
||||
|
||||
func (v SampleValue) String() string {
|
||||
return strconv.FormatFloat(float64(v), 'f', -1, 64)
|
||||
}
|
||||
|
||||
// SamplePair pairs a SampleValue with a Timestamp.
|
||||
type SamplePair struct {
|
||||
Timestamp Time
|
||||
Value SampleValue
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (s SamplePair) MarshalJSON() ([]byte, error) {
|
||||
t, err := json.Marshal(s.Timestamp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v, err := json.Marshal(s.Value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []byte(fmt.Sprintf("[%s,%s]", t, v)), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (s *SamplePair) UnmarshalJSON(b []byte) error {
|
||||
v := [...]json.Unmarshaler{&s.Timestamp, &s.Value}
|
||||
return json.Unmarshal(b, &v)
|
||||
}
|
||||
|
||||
// Equal returns true if this SamplePair and o have equal Values and equal
|
||||
// Timestamps. The semantics of Value equality is defined by SampleValue.Equal.
|
||||
func (s *SamplePair) Equal(o *SamplePair) bool {
|
||||
return s == o || (s.Value.Equal(o.Value) && s.Timestamp.Equal(o.Timestamp))
|
||||
}
|
||||
|
||||
func (s SamplePair) String() string {
|
||||
return fmt.Sprintf("%s @[%s]", s.Value, s.Timestamp)
|
||||
}
|
||||
|
||||
// Sample is a sample pair associated with a metric.
|
||||
type Sample struct {
|
||||
Metric Metric `json:"metric"`
|
||||
Value SampleValue `json:"value"`
|
||||
Timestamp Time `json:"timestamp"`
|
||||
}
|
||||
|
||||
// Equal compares first the metrics, then the timestamp, then the value. The
|
||||
// semantics of value equality is defined by SampleValue.Equal.
|
||||
func (s *Sample) Equal(o *Sample) bool {
|
||||
if s == o {
|
||||
return true
|
||||
}
|
||||
|
||||
if !s.Metric.Equal(o.Metric) {
|
||||
return false
|
||||
}
|
||||
if !s.Timestamp.Equal(o.Timestamp) {
|
||||
return false
|
||||
}
|
||||
|
||||
return s.Value.Equal(o.Value)
|
||||
}
|
||||
|
||||
func (s Sample) String() string {
|
||||
return fmt.Sprintf("%s => %s", s.Metric, SamplePair{
|
||||
Timestamp: s.Timestamp,
|
||||
Value: s.Value,
|
||||
})
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (s Sample) MarshalJSON() ([]byte, error) {
|
||||
v := struct {
|
||||
Metric Metric `json:"metric"`
|
||||
Value SamplePair `json:"value"`
|
||||
}{
|
||||
Metric: s.Metric,
|
||||
Value: SamplePair{
|
||||
Timestamp: s.Timestamp,
|
||||
Value: s.Value,
|
||||
},
|
||||
}
|
||||
|
||||
return json.Marshal(&v)
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (s *Sample) UnmarshalJSON(b []byte) error {
|
||||
v := struct {
|
||||
Metric Metric `json:"metric"`
|
||||
Value SamplePair `json:"value"`
|
||||
}{
|
||||
Metric: s.Metric,
|
||||
Value: SamplePair{
|
||||
Timestamp: s.Timestamp,
|
||||
Value: s.Value,
|
||||
},
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(b, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s.Metric = v.Metric
|
||||
s.Timestamp = v.Value.Timestamp
|
||||
s.Value = v.Value.Value
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Samples is a sortable Sample slice. It implements sort.Interface.
|
||||
type Samples []*Sample
|
||||
|
||||
func (s Samples) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
// Less compares first the metrics, then the timestamp.
|
||||
func (s Samples) Less(i, j int) bool {
|
||||
switch {
|
||||
case s[i].Metric.Before(s[j].Metric):
|
||||
return true
|
||||
case s[j].Metric.Before(s[i].Metric):
|
||||
return false
|
||||
case s[i].Timestamp.Before(s[j].Timestamp):
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (s Samples) Swap(i, j int) {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
|
||||
// Equal compares two sets of samples and returns true if they are equal.
|
||||
func (s Samples) Equal(o Samples) bool {
|
||||
if len(s) != len(o) {
|
||||
return false
|
||||
}
|
||||
|
||||
for i, sample := range s {
|
||||
if !sample.Equal(o[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// SampleStream is a stream of Values belonging to an attached COWMetric.
|
||||
type SampleStream struct {
|
||||
Metric Metric `json:"metric"`
|
||||
Values []SamplePair `json:"values"`
|
||||
}
|
||||
|
||||
func (ss SampleStream) String() string {
|
||||
vals := make([]string, len(ss.Values))
|
||||
for i, v := range ss.Values {
|
||||
vals[i] = v.String()
|
||||
}
|
||||
return fmt.Sprintf("%s =>\n%s", ss.Metric, strings.Join(vals, "\n"))
|
||||
}
|
||||
|
||||
// Value is a generic interface for values resulting from a query evaluation.
|
||||
type Value interface {
|
||||
Type() ValueType
|
||||
String() string
|
||||
}
|
||||
|
||||
func (Matrix) Type() ValueType { return ValMatrix }
|
||||
func (Vector) Type() ValueType { return ValVector }
|
||||
func (*Scalar) Type() ValueType { return ValScalar }
|
||||
func (*String) Type() ValueType { return ValString }
|
||||
|
||||
type ValueType int
|
||||
|
||||
const (
|
||||
ValNone ValueType = iota
|
||||
ValScalar
|
||||
ValVector
|
||||
ValMatrix
|
||||
ValString
|
||||
)
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (et ValueType) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(et.String())
|
||||
}
|
||||
|
||||
func (et *ValueType) UnmarshalJSON(b []byte) error {
|
||||
var s string
|
||||
if err := json.Unmarshal(b, &s); err != nil {
|
||||
return err
|
||||
}
|
||||
switch s {
|
||||
case "<ValNone>":
|
||||
*et = ValNone
|
||||
case "scalar":
|
||||
*et = ValScalar
|
||||
case "vector":
|
||||
*et = ValVector
|
||||
case "matrix":
|
||||
*et = ValMatrix
|
||||
case "string":
|
||||
*et = ValString
|
||||
default:
|
||||
return fmt.Errorf("unknown value type %q", s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e ValueType) String() string {
|
||||
switch e {
|
||||
case ValNone:
|
||||
return "<ValNone>"
|
||||
case ValScalar:
|
||||
return "scalar"
|
||||
case ValVector:
|
||||
return "vector"
|
||||
case ValMatrix:
|
||||
return "matrix"
|
||||
case ValString:
|
||||
return "string"
|
||||
}
|
||||
panic("ValueType.String: unhandled value type")
|
||||
}
|
||||
|
||||
// Scalar is a scalar value evaluated at the set timestamp.
|
||||
type Scalar struct {
|
||||
Value SampleValue `json:"value"`
|
||||
Timestamp Time `json:"timestamp"`
|
||||
}
|
||||
|
||||
func (s Scalar) String() string {
|
||||
return fmt.Sprintf("scalar: %v @[%v]", s.Value, s.Timestamp)
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (s Scalar) MarshalJSON() ([]byte, error) {
|
||||
v := strconv.FormatFloat(float64(s.Value), 'f', -1, 64)
|
||||
return json.Marshal([...]interface{}{s.Timestamp, string(v)})
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (s *Scalar) UnmarshalJSON(b []byte) error {
|
||||
var f string
|
||||
v := [...]interface{}{&s.Timestamp, &f}
|
||||
|
||||
if err := json.Unmarshal(b, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
value, err := strconv.ParseFloat(f, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing sample value: %s", err)
|
||||
}
|
||||
s.Value = SampleValue(value)
|
||||
return nil
|
||||
}
|
||||
|
||||
// String is a string value evaluated at the set timestamp.
|
||||
type String struct {
|
||||
Value string `json:"value"`
|
||||
Timestamp Time `json:"timestamp"`
|
||||
}
|
||||
|
||||
func (s *String) String() string {
|
||||
return s.Value
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (s String) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal([]interface{}{s.Timestamp, s.Value})
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (s *String) UnmarshalJSON(b []byte) error {
|
||||
v := [...]interface{}{&s.Timestamp, &s.Value}
|
||||
return json.Unmarshal(b, &v)
|
||||
}
|
||||
|
||||
// Vector is basically only an alias for Samples, but the
|
||||
// contract is that in a Vector, all Samples have the same timestamp.
|
||||
type Vector []*Sample
|
||||
|
||||
func (vec Vector) String() string {
|
||||
entries := make([]string, len(vec))
|
||||
for i, s := range vec {
|
||||
entries[i] = s.String()
|
||||
}
|
||||
return strings.Join(entries, "\n")
|
||||
}
|
||||
|
||||
func (vec Vector) Len() int { return len(vec) }
|
||||
func (vec Vector) Swap(i, j int) { vec[i], vec[j] = vec[j], vec[i] }
|
||||
|
||||
// Less compares first the metrics, then the timestamp.
|
||||
func (vec Vector) Less(i, j int) bool {
|
||||
switch {
|
||||
case vec[i].Metric.Before(vec[j].Metric):
|
||||
return true
|
||||
case vec[j].Metric.Before(vec[i].Metric):
|
||||
return false
|
||||
case vec[i].Timestamp.Before(vec[j].Timestamp):
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Equal compares two sets of samples and returns true if they are equal.
|
||||
func (vec Vector) Equal(o Vector) bool {
|
||||
if len(vec) != len(o) {
|
||||
return false
|
||||
}
|
||||
|
||||
for i, sample := range vec {
|
||||
if !sample.Equal(o[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Matrix is a list of time series.
|
||||
type Matrix []*SampleStream
|
||||
|
||||
func (m Matrix) Len() int { return len(m) }
|
||||
func (m Matrix) Less(i, j int) bool { return m[i].Metric.Before(m[j].Metric) }
|
||||
func (m Matrix) Swap(i, j int) { m[i], m[j] = m[j], m[i] }
|
||||
|
||||
func (mat Matrix) String() string {
|
||||
matCp := make(Matrix, len(mat))
|
||||
copy(matCp, mat)
|
||||
sort.Sort(matCp)
|
||||
|
||||
strs := make([]string, len(matCp))
|
||||
|
||||
for i, ss := range matCp {
|
||||
strs[i] = ss.String()
|
||||
}
|
||||
|
||||
return strings.Join(strs, "\n")
|
||||
}
|
Reference in New Issue
Block a user