Source File
view.go
Belonging Package
go.opencensus.io/stats/view
package view
import (
)
type View struct {
Name string // Name of View. Must be unique. If unset, will default to the name of the Measure.
Description string // Description is a human-readable description for this view.
var ErrNegativeBucketBounds = errors.New("negative bucket bounds not supported")
func ( *View) () error {
if .Measure == nil {
return fmt.Errorf("cannot register view %q: measure not set", .Name)
}
if .Aggregation == nil {
return fmt.Errorf("cannot register view %q: aggregation not set", .Name)
}
if .Name == "" {
.Name = .Measure.Name()
}
if .Description == "" {
.Description = .Measure.Description()
}
if := checkViewName(.Name); != nil {
return
}
sort.Slice(.TagKeys, func(, int) bool {
return .TagKeys[].Name() < .TagKeys[].Name()
})
sort.Float64s(.Aggregation.Buckets)
for , := range .Aggregation.Buckets {
if < 0 {
return ErrNegativeBucketBounds
}
.Aggregation.Buckets = dropZeroBounds(.Aggregation.Buckets...)
return nil
}
func ( ...float64) []float64 {
for , := range {
if > 0 {
return [:]
}
}
return []float64{}
}
type viewInternal struct {
view *View // view is the canonicalized View definition associated with this view.
subscribed uint32 // 1 if someone is subscribed and data need to be exported, use atomic to access
collector *collector
metricDescriptor *metricdata.Descriptor
}
func ( *View) (*viewInternal, error) {
return &viewInternal{
view: ,
collector: &collector{make(map[string]AggregationData), .Aggregation},
metricDescriptor: viewToMetricDescriptor(),
}, nil
}
func ( *viewInternal) () {
atomic.StoreUint32(&.subscribed, 1)
}
func ( *viewInternal) () {
atomic.StoreUint32(&.subscribed, 0)
}
func ( *viewInternal) () bool {
return atomic.LoadUint32(&.subscribed) == 1
}
func ( *viewInternal) () {
.collector.clearRows()
}
func ( *viewInternal) () []*Row {
return .collector.collectedRows(.view.TagKeys)
}
func ( *viewInternal) ( *tag.Map, float64, map[string]interface{}, time.Time) {
if !.isSubscribed() {
return
}
:= string(encodeWithKeys(, .view.TagKeys))
.collector.addSample(, , , )
}
type Row struct {
Tags []tag.Tag
Data AggregationData
}
func ( *Row) () string {
var bytes.Buffer
.WriteString("{ ")
.WriteString("{ ")
for , := range .Tags {
.WriteString(fmt.Sprintf("{%v %v}", .Key.Name(), .Value))
}
.WriteString(" }")
.WriteString(fmt.Sprintf("%v", .Data))
.WriteString(" }")
return .String()
}
func ( string) bool {
for , := range {
if !( >= ' ' && <= '~') {
return false
}
}
return true
}
func ( string) error {
if len() > maxNameLength {
return fmt.Errorf("view name cannot be larger than %v", maxNameLength)
}
if !isPrintable() {
return fmt.Errorf("view name needs to be an ASCII string")
}
return nil
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |