mirror of
https://github.com/hanzoai/visor.git
synced 2026-09-24 17:04:14 +00:00
A prometheus Data held its labels in a map, and control.ExecArgs held the live kernel objects an exec runs against -- a mount namespace, an fd table, a limit set. Neither has offsets, so neither payload could state a layout. Labels become a list, which also retires the O(n^2) walk that existed to read a map in sorted order. The kernel objects move to control.Env, which is what the sentry supplies and what a call arriving on the wire cannot: a namespace is a reference, not a value. Every urpc payload now states its own wire. Co-authored-by: Hanzo Dev <[email protected]>
518 lines
12 KiB
Go
518 lines
12 KiB
Go
// Copyright 2026 The gVisor 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.
|
|
|
|
// Code generated by zip; DO NOT EDIT.
|
|
|
|
package prometheus
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"fmt"
|
|
"strings"
|
|
|
|
zap "github.com/zap-proto/go"
|
|
)
|
|
|
|
// ---- Bucket ------------------------------------------------------------
|
|
|
|
const (
|
|
bucketUpperBoundAt = 0
|
|
bucketSamplesAt = 8
|
|
bucketSize = 16
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*Bucket)(nil)
|
|
|
|
// MarshalZAP writes Bucket from constant offsets.
|
|
func (x *Bucket) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(bucketSize + 256)
|
|
ob := b.StartObject(bucketSize)
|
|
innerUpperBound, err := x.UpperBound.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(bucketUpperBoundAt, innerUpperBound)
|
|
ob.SetUint64(bucketSamplesAt, uint64(x.Samples))
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads Bucket out of the buffer that arrived.
|
|
func (x *Bucket) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("Bucket: %w", err)
|
|
}
|
|
o := m.Root()
|
|
if raw := o.Bytes(bucketUpperBoundAt); len(raw) > 0 {
|
|
if err := x.UpperBound.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
x.Samples = uint64(o.Uint64(bucketSamplesAt))
|
|
return nil
|
|
}
|
|
|
|
// ---- Data --------------------------------------------------------------
|
|
|
|
const (
|
|
dataMetricAt = 0
|
|
dataLabelsAt = 8
|
|
dataExternalLabelsAt = 16
|
|
dataNumberAt = 24
|
|
dataHistogramValueAt = 32
|
|
dataSize = 40
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*Data)(nil)
|
|
|
|
// MarshalZAP writes Data from constant offsets.
|
|
func (x *Data) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(dataSize + 256)
|
|
labelsAt, labelsN := 0, len(x.Labels)
|
|
if labelsN > 0 {
|
|
var blob []byte
|
|
for i := range x.Labels {
|
|
enc, err := x.Labels[i].MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var n [4]byte
|
|
binary.LittleEndian.PutUint32(n[:], uint32(len(enc)))
|
|
blob = append(blob, n[:]...)
|
|
blob = append(blob, enc...)
|
|
}
|
|
labelsAt = b.WriteBytes(blob)
|
|
}
|
|
externalLabelsAt, externalLabelsN := 0, len(x.ExternalLabels)
|
|
if externalLabelsN > 0 {
|
|
var blob []byte
|
|
for i := range x.ExternalLabels {
|
|
enc, err := x.ExternalLabels[i].MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var n [4]byte
|
|
binary.LittleEndian.PutUint32(n[:], uint32(len(enc)))
|
|
blob = append(blob, n[:]...)
|
|
blob = append(blob, enc...)
|
|
}
|
|
externalLabelsAt = b.WriteBytes(blob)
|
|
}
|
|
ob := b.StartObject(dataSize)
|
|
if x.Metric != nil {
|
|
innerMetric, err := x.Metric.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(dataMetricAt, innerMetric)
|
|
}
|
|
if x.Number != nil {
|
|
innerNumber, err := x.Number.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(dataNumberAt, innerNumber)
|
|
}
|
|
if x.HistogramValue != nil {
|
|
innerHistogramValue, err := x.HistogramValue.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(dataHistogramValueAt, innerHistogramValue)
|
|
}
|
|
if labelsN > 0 {
|
|
ob.SetList(dataLabelsAt, labelsAt, labelsN)
|
|
}
|
|
if externalLabelsN > 0 {
|
|
ob.SetList(dataExternalLabelsAt, externalLabelsAt, externalLabelsN)
|
|
}
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads Data out of the buffer that arrived.
|
|
func (x *Data) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("Data: %w", err)
|
|
}
|
|
o := m.Root()
|
|
if raw := o.Bytes(dataMetricAt); len(raw) > 0 {
|
|
var v Metric
|
|
if err := v.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
x.Metric = &v
|
|
}
|
|
if l := o.List(dataLabelsAt); l.Len() > 0 {
|
|
rows := make([]Label, l.Len())
|
|
for i := range rows {
|
|
if err := rows[i].UnmarshalZAP(l.BytesAt(i)); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
x.Labels = rows
|
|
}
|
|
if l := o.List(dataExternalLabelsAt); l.Len() > 0 {
|
|
rows := make([]Label, l.Len())
|
|
for i := range rows {
|
|
if err := rows[i].UnmarshalZAP(l.BytesAt(i)); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
x.ExternalLabels = rows
|
|
}
|
|
if raw := o.Bytes(dataNumberAt); len(raw) > 0 {
|
|
var v Number
|
|
if err := v.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
x.Number = &v
|
|
}
|
|
if raw := o.Bytes(dataHistogramValueAt); len(raw) > 0 {
|
|
var v Histogram
|
|
if err := v.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
x.HistogramValue = &v
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ---- Histogram ---------------------------------------------------------
|
|
|
|
const (
|
|
histogramTotalAt = 0
|
|
histogramMinAt = 8
|
|
histogramMaxAt = 16
|
|
histogramSumOfSquaredDeviationsAt = 24
|
|
histogramBucketsAt = 32
|
|
histogramSize = 40
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*Histogram)(nil)
|
|
|
|
// MarshalZAP writes Histogram from constant offsets.
|
|
func (x *Histogram) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(histogramSize + 256)
|
|
bucketsAt, bucketsN := 0, len(x.Buckets)
|
|
if bucketsN > 0 {
|
|
var blob []byte
|
|
for i := range x.Buckets {
|
|
enc, err := x.Buckets[i].MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var n [4]byte
|
|
binary.LittleEndian.PutUint32(n[:], uint32(len(enc)))
|
|
blob = append(blob, n[:]...)
|
|
blob = append(blob, enc...)
|
|
}
|
|
bucketsAt = b.WriteBytes(blob)
|
|
}
|
|
ob := b.StartObject(histogramSize)
|
|
innerTotal, err := x.Total.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(histogramTotalAt, innerTotal)
|
|
innerMin, err := x.Min.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(histogramMinAt, innerMin)
|
|
innerMax, err := x.Max.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(histogramMaxAt, innerMax)
|
|
innerSumOfSquaredDeviations, err := x.SumOfSquaredDeviations.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(histogramSumOfSquaredDeviationsAt, innerSumOfSquaredDeviations)
|
|
if bucketsN > 0 {
|
|
ob.SetList(histogramBucketsAt, bucketsAt, bucketsN)
|
|
}
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads Histogram out of the buffer that arrived.
|
|
func (x *Histogram) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("Histogram: %w", err)
|
|
}
|
|
o := m.Root()
|
|
if raw := o.Bytes(histogramTotalAt); len(raw) > 0 {
|
|
if err := x.Total.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if raw := o.Bytes(histogramMinAt); len(raw) > 0 {
|
|
if err := x.Min.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if raw := o.Bytes(histogramMaxAt); len(raw) > 0 {
|
|
if err := x.Max.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if raw := o.Bytes(histogramSumOfSquaredDeviationsAt); len(raw) > 0 {
|
|
if err := x.SumOfSquaredDeviations.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if l := o.List(histogramBucketsAt); l.Len() > 0 {
|
|
rows := make([]Bucket, l.Len())
|
|
for i := range rows {
|
|
if err := rows[i].UnmarshalZAP(l.BytesAt(i)); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
x.Buckets = rows
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ---- Label -------------------------------------------------------------
|
|
|
|
const (
|
|
labelKeyAt = 0
|
|
labelValueAt = 8
|
|
labelSize = 16
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*Label)(nil)
|
|
|
|
// MarshalZAP writes Label from constant offsets.
|
|
func (x *Label) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(labelSize + 256)
|
|
ob := b.StartObject(labelSize)
|
|
ob.SetText(labelKeyAt, string(x.Key))
|
|
ob.SetText(labelValueAt, string(x.Value))
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads Label out of the buffer that arrived.
|
|
func (x *Label) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("Label: %w", err)
|
|
}
|
|
o := m.Root()
|
|
x.Key = string(strings.Clone(o.Text(labelKeyAt)))
|
|
x.Value = string(strings.Clone(o.Text(labelValueAt)))
|
|
return nil
|
|
}
|
|
|
|
// ---- Metric ------------------------------------------------------------
|
|
|
|
const (
|
|
metricNameAt = 0
|
|
metricTypeAt = 8
|
|
metricHelpAt = 16
|
|
metricSize = 24
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*Metric)(nil)
|
|
|
|
// MarshalZAP writes Metric from constant offsets.
|
|
func (x *Metric) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(metricSize + 256)
|
|
ob := b.StartObject(metricSize)
|
|
ob.SetText(metricNameAt, string(x.Name))
|
|
ob.SetInt64(metricTypeAt, int64(x.Type))
|
|
ob.SetText(metricHelpAt, string(x.Help))
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads Metric out of the buffer that arrived.
|
|
func (x *Metric) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("Metric: %w", err)
|
|
}
|
|
o := m.Root()
|
|
x.Name = string(strings.Clone(o.Text(metricNameAt)))
|
|
x.Type = Type(o.Int64(metricTypeAt))
|
|
x.Help = string(strings.Clone(o.Text(metricHelpAt)))
|
|
return nil
|
|
}
|
|
|
|
// ---- Number ------------------------------------------------------------
|
|
|
|
const (
|
|
numberFloatAt = 0
|
|
numberIntAt = 8
|
|
numberSize = 16
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*Number)(nil)
|
|
|
|
// MarshalZAP writes Number from constant offsets.
|
|
func (x *Number) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(numberSize + 256)
|
|
ob := b.StartObject(numberSize)
|
|
ob.SetFloat64(numberFloatAt, float64(x.Float))
|
|
ob.SetInt64(numberIntAt, int64(x.Int))
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads Number out of the buffer that arrived.
|
|
func (x *Number) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("Number: %w", err)
|
|
}
|
|
o := m.Root()
|
|
x.Float = float64(o.Float64(numberFloatAt))
|
|
x.Int = int64(o.Int64(numberIntAt))
|
|
return nil
|
|
}
|
|
|
|
// ---- Snapshot ----------------------------------------------------------
|
|
|
|
const (
|
|
snapshotWhenAt = 0
|
|
snapshotDataAt = 8
|
|
snapshotSize = 16
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*Snapshot)(nil)
|
|
|
|
// MarshalZAP writes Snapshot from constant offsets.
|
|
func (x *Snapshot) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(snapshotSize + 256)
|
|
dataAt, dataN := 0, len(x.Data)
|
|
if dataN > 0 {
|
|
var blob []byte
|
|
for i := range x.Data {
|
|
elem := x.Data[i]
|
|
if elem == nil {
|
|
elem = new(Data)
|
|
}
|
|
enc, err := elem.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var n [4]byte
|
|
binary.LittleEndian.PutUint32(n[:], uint32(len(enc)))
|
|
blob = append(blob, n[:]...)
|
|
blob = append(blob, enc...)
|
|
}
|
|
dataAt = b.WriteBytes(blob)
|
|
}
|
|
ob := b.StartObject(snapshotSize)
|
|
{
|
|
eb := zap.NewBuilder(zap.HeaderSize)
|
|
eb.StartObject(0).FinishAsRoot()
|
|
ob.SetBytes(snapshotWhenAt, eb.Finish())
|
|
}
|
|
if dataN > 0 {
|
|
ob.SetList(snapshotDataAt, dataAt, dataN)
|
|
}
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads Snapshot out of the buffer that arrived.
|
|
func (x *Snapshot) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("Snapshot: %w", err)
|
|
}
|
|
o := m.Root()
|
|
if l := o.List(snapshotDataAt); l.Len() > 0 {
|
|
rows := make([]*Data, l.Len())
|
|
for i := range rows {
|
|
rows[i] = new(Data)
|
|
if err := rows[i].UnmarshalZAP(l.BytesAt(i)); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
x.Data = rows
|
|
}
|
|
return nil
|
|
}
|