metrics

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2025 License: MIT Imports: 20 Imported by: 1

Documentation

Index

Constants

View Source
const APIPathPrefix = "/twirp/metrics.API/"

APIPathPrefix is a convenience constant that may identify URL paths. Should be used with caution, it only matches routes generated by Twirp Go clients, with the default "/twirp" prefix and default CamelCase service and method names. More info: https://twitchtv.github.io/twirp/docs/routing.html

Variables

View Source
var File_pbf_metrics_api_proto protoreflect.FileDescriptor
View Source
var File_pbf_metrics_common_proto protoreflect.FileDescriptor
View Source
var File_pbf_metrics_counter_proto protoreflect.FileDescriptor
View Source
var File_pbf_metrics_gauge_proto protoreflect.FileDescriptor
View Source
var File_pbf_metrics_histogram_proto protoreflect.FileDescriptor

Functions

func WriteError

func WriteError(resp http.ResponseWriter, err error)

WriteError writes an HTTP response with a valid Twirp error format (code, msg, meta). Useful outside of the Twirp server (e.g. http middleware), but does not trigger hooks. If err is not a twirp.Error, it will get wrapped with twirp.InternalErrorWith(err)

Types

type API

type API interface {
	Counter(context.Context, *CounterI) (*CounterO, error)

	Gauge(context.Context, *GaugeI) (*GaugeO, error)

	Histogram(context.Context, *HistogramI) (*HistogramO, error)
}

func NewAPIJSONClient

func NewAPIJSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) API

NewAPIJSONClient creates a JSON client that implements the API interface. It communicates using JSON and can be configured with a custom HTTPClient.

func NewAPIProtobufClient

func NewAPIProtobufClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) API

NewAPIProtobufClient creates a Protobuf client that implements the API interface. It communicates using Protobuf and can be configured with a custom HTTPClient.

type Action

type Action struct {

	// labels is the optional set of key-value pairs whitelisted per metric.
	// Providing labels that are not whitelisted causes the entire RPC to be
	// rejected on a request level.
	Labels map[string]string `` /* 141-byte string literal not displayed */
	// metric is the required metric name in camel case format. Providing metric
	// names that are not whitelisted causes the entire RPC to be rejected on a
	// request level. Metric names must not be longer than 255 characters.
	Metric string `protobuf:"bytes,200,opt,name=metric,proto3" json:"metric,omitempty"`
	// number is the required floating point value that should be applied to the
	// timeseries specified by the labels and metric properties. Negative values
	// may cause the entire RPC to be rejected on a per metric basis.
	Number float64 `protobuf:"fixed64,300,opt,name=number,proto3" json:"number,omitempty"`
	// contains filtered or unexported fields
}

Action is the request body for any given action.

{
    "labels": {
        "key": "value"
    },
    "metric": "teams_bridge_error_total",
    "values": [
        1
    ]
}

func (*Action) Descriptor deprecated

func (*Action) Descriptor() ([]byte, []int)

Deprecated: Use Action.ProtoReflect.Descriptor instead.

func (*Action) GetLabels

func (x *Action) GetLabels() map[string]string

func (*Action) GetMetric

func (x *Action) GetMetric() string

func (*Action) GetNumber

func (x *Action) GetNumber() float64

func (*Action) ProtoMessage

func (*Action) ProtoMessage()

func (*Action) ProtoReflect

func (x *Action) ProtoReflect() protoreflect.Message

func (*Action) Reset

func (x *Action) Reset()

func (*Action) String

func (x *Action) String() string

type CounterI

type CounterI struct {
	Action []*Action `protobuf:"bytes,100,rep,name=action,proto3" json:"action,omitempty"`
	// contains filtered or unexported fields
}

CounterI is the input for updating counters.

func (*CounterI) Descriptor deprecated

func (*CounterI) Descriptor() ([]byte, []int)

Deprecated: Use CounterI.ProtoReflect.Descriptor instead.

func (*CounterI) GetAction

func (x *CounterI) GetAction() []*Action

func (*CounterI) ProtoMessage

func (*CounterI) ProtoMessage()

func (*CounterI) ProtoReflect

func (x *CounterI) ProtoReflect() protoreflect.Message

func (*CounterI) Reset

func (x *CounterI) Reset()

func (*CounterI) String

func (x *CounterI) String() string

type CounterO

type CounterO struct {
	Result []*Result `protobuf:"bytes,100,rep,name=result,proto3" json:"result,omitempty"`
	// contains filtered or unexported fields
}

CounterO is the output for updating counters.

func (*CounterO) Descriptor deprecated

func (*CounterO) Descriptor() ([]byte, []int)

Deprecated: Use CounterO.ProtoReflect.Descriptor instead.

func (*CounterO) GetResult

func (x *CounterO) GetResult() []*Result

func (*CounterO) ProtoMessage

func (*CounterO) ProtoMessage()

func (*CounterO) ProtoReflect

func (x *CounterO) ProtoReflect() protoreflect.Message

func (*CounterO) Reset

func (x *CounterO) Reset()

func (*CounterO) String

func (x *CounterO) String() string

type GaugeI

type GaugeI struct {
	Action []*Action `protobuf:"bytes,100,rep,name=action,proto3" json:"action,omitempty"`
	// contains filtered or unexported fields
}

GaugeI is the input for updating gauges.

func (*GaugeI) Descriptor deprecated

func (*GaugeI) Descriptor() ([]byte, []int)

Deprecated: Use GaugeI.ProtoReflect.Descriptor instead.

func (*GaugeI) GetAction

func (x *GaugeI) GetAction() []*Action

func (*GaugeI) ProtoMessage

func (*GaugeI) ProtoMessage()

func (*GaugeI) ProtoReflect

func (x *GaugeI) ProtoReflect() protoreflect.Message

func (*GaugeI) Reset

func (x *GaugeI) Reset()

func (*GaugeI) String

func (x *GaugeI) String() string

type GaugeO

type GaugeO struct {
	Result []*Result `protobuf:"bytes,100,rep,name=result,proto3" json:"result,omitempty"`
	// contains filtered or unexported fields
}

GaugeO is the output for updating gauges.

func (*GaugeO) Descriptor deprecated

func (*GaugeO) Descriptor() ([]byte, []int)

Deprecated: Use GaugeO.ProtoReflect.Descriptor instead.

func (*GaugeO) GetResult

func (x *GaugeO) GetResult() []*Result

func (*GaugeO) ProtoMessage

func (*GaugeO) ProtoMessage()

func (*GaugeO) ProtoReflect

func (x *GaugeO) ProtoReflect() protoreflect.Message

func (*GaugeO) Reset

func (x *GaugeO) Reset()

func (*GaugeO) String

func (x *GaugeO) String() string

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is the interface used by generated clients to send HTTP requests. It is fulfilled by *(net/http).Client, which is sufficient for most users. Users can provide their own implementation for special retry policies.

HTTPClient implementations should not follow redirects. Redirects are automatically disabled if *(net/http).Client is passed to client constructors. See the withoutRedirects function in this file for more details.

type HistogramI

type HistogramI struct {
	Action []*Action `protobuf:"bytes,100,rep,name=action,proto3" json:"action,omitempty"`
	// contains filtered or unexported fields
}

HistogramI is the input for updating histograms.

func (*HistogramI) Descriptor deprecated

func (*HistogramI) Descriptor() ([]byte, []int)

Deprecated: Use HistogramI.ProtoReflect.Descriptor instead.

func (*HistogramI) GetAction

func (x *HistogramI) GetAction() []*Action

func (*HistogramI) ProtoMessage

func (*HistogramI) ProtoMessage()

func (*HistogramI) ProtoReflect

func (x *HistogramI) ProtoReflect() protoreflect.Message

func (*HistogramI) Reset

func (x *HistogramI) Reset()

func (*HistogramI) String

func (x *HistogramI) String() string

type HistogramO

type HistogramO struct {
	Result []*Result `protobuf:"bytes,100,rep,name=result,proto3" json:"result,omitempty"`
	// contains filtered or unexported fields
}

HistogramO is the output for updating histograms.

func (*HistogramO) Descriptor deprecated

func (*HistogramO) Descriptor() ([]byte, []int)

Deprecated: Use HistogramO.ProtoReflect.Descriptor instead.

func (*HistogramO) GetResult

func (x *HistogramO) GetResult() []*Result

func (*HistogramO) ProtoMessage

func (*HistogramO) ProtoMessage()

func (*HistogramO) ProtoReflect

func (x *HistogramO) ProtoReflect() protoreflect.Message

func (*HistogramO) Reset

func (x *HistogramO) Reset()

func (*HistogramO) String

func (x *HistogramO) String() string

type Reason

type Reason struct {
	Info string `protobuf:"bytes,100,opt,name=info,proto3" json:"info,omitempty"`
	Kind string `protobuf:"bytes,200,opt,name=kind,proto3" json:"kind,omitempty"`
	// contains filtered or unexported fields
}

func (*Reason) Descriptor deprecated

func (*Reason) Descriptor() ([]byte, []int)

Deprecated: Use Reason.ProtoReflect.Descriptor instead.

func (*Reason) GetInfo

func (x *Reason) GetInfo() string

func (*Reason) GetKind

func (x *Reason) GetKind() string

func (*Reason) ProtoMessage

func (*Reason) ProtoMessage()

func (*Reason) ProtoReflect

func (x *Reason) ProtoReflect() protoreflect.Message

func (*Reason) Reset

func (x *Reason) Reset()

func (*Reason) String

func (x *Reason) String() string

type Result

type Result struct {

	// reason is the optional feedback that the backend provides in case of
	// action failure.
	Reason *Reason `protobuf:"bytes,100,opt,name=reason,proto3,oneof" json:"reason,omitempty"`
	// status is the final state of the executed action.
	//
	//	success, the given actions were executed successfully
	//
	//	failure, the given actions were rejected for reasons
	Status string `protobuf:"bytes,200,opt,name=status,proto3" json:"status,omitempty"`
	// contains filtered or unexported fields
}

Result is the response body for any given action.

{
    "reason": {
        "desc": "This is why the request was rejected.",
        "kind": "someErrorCode"
    },
    "status": "failure"
}

func (*Result) Descriptor deprecated

func (*Result) Descriptor() ([]byte, []int)

Deprecated: Use Result.ProtoReflect.Descriptor instead.

func (*Result) GetReason

func (x *Result) GetReason() *Reason

func (*Result) GetStatus

func (x *Result) GetStatus() string

func (*Result) ProtoMessage

func (*Result) ProtoMessage()

func (*Result) ProtoReflect

func (x *Result) ProtoReflect() protoreflect.Message

func (*Result) Reset

func (x *Result) Reset()

func (*Result) String

func (x *Result) String() string

type TwirpServer

type TwirpServer interface {
	http.Handler

	// ServiceDescriptor returns gzipped bytes describing the .proto file that
	// this service was generated from. Once unzipped, the bytes can be
	// unmarshalled as a
	// google.golang.org/protobuf/types/descriptorpb.FileDescriptorProto.
	//
	// The returned integer is the index of this particular service within that
	// FileDescriptorProto's 'Service' slice of ServiceDescriptorProtos. This is a
	// low-level field, expected to be used for reflection.
	ServiceDescriptor() ([]byte, int)

	// ProtocGenTwirpVersion is the semantic version string of the version of
	// twirp used to generate this file.
	ProtocGenTwirpVersion() string

	// PathPrefix returns the HTTP URL path prefix for all methods handled by this
	// service. This can be used with an HTTP mux to route Twirp requests.
	// The path prefix is in the form: "/<prefix>/<package>.<Service>/"
	// that is, everything in a Twirp route except for the <Method> at the end.
	PathPrefix() string
}

TwirpServer is the interface generated server structs will support: they're HTTP handlers with additional methods for accessing metadata about the service. Those accessors are a low-level API for building reflection tools. Most people can think of TwirpServers as just http.Handlers.

func NewAPIServer

func NewAPIServer(svc API, opts ...interface{}) TwirpServer

NewAPIServer builds a TwirpServer that can be used as an http.Handler to handle HTTP requests that are routed to the right method in the provided svc implementation. The opts are twirp.ServerOption modifiers, for example twirp.WithServerHooks(hooks).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL