Documentation
¶
Index ¶
- Constants
- Variables
- func WriteError(resp http.ResponseWriter, err error)
- type API
- type Action
- func (*Action) Descriptor() ([]byte, []int)deprecated
- func (x *Action) GetLabels() map[string]string
- func (x *Action) GetMetric() string
- func (x *Action) GetNumber() float64
- func (*Action) ProtoMessage()
- func (x *Action) ProtoReflect() protoreflect.Message
- func (x *Action) Reset()
- func (x *Action) String() string
- type CounterI
- type CounterO
- type GaugeI
- type GaugeO
- type HTTPClient
- type HistogramI
- type HistogramO
- type Reason
- type Result
- type TwirpServer
Constants ¶
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 ¶
var File_pbf_metrics_api_proto protoreflect.FileDescriptor
var File_pbf_metrics_common_proto protoreflect.FileDescriptor
var File_pbf_metrics_counter_proto protoreflect.FileDescriptor
var File_pbf_metrics_gauge_proto protoreflect.FileDescriptor
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) ProtoMessage ¶
func (*Action) ProtoMessage()
func (*Action) ProtoReflect ¶
func (x *Action) ProtoReflect() protoreflect.Message
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) ProtoMessage ¶
func (*CounterI) ProtoMessage()
func (*CounterI) ProtoReflect ¶
func (x *CounterI) ProtoReflect() protoreflect.Message
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) ProtoMessage ¶
func (*CounterO) ProtoMessage()
func (*CounterO) ProtoReflect ¶
func (x *CounterO) ProtoReflect() protoreflect.Message
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) ProtoMessage ¶
func (*GaugeI) ProtoMessage()
func (*GaugeI) ProtoReflect ¶
func (x *GaugeI) ProtoReflect() protoreflect.Message
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) ProtoMessage ¶
func (*GaugeO) ProtoMessage()
func (*GaugeO) ProtoReflect ¶
func (x *GaugeO) ProtoReflect() protoreflect.Message
type HTTPClient ¶
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) ProtoMessage ¶
func (*Reason) ProtoMessage()
func (*Reason) ProtoReflect ¶
func (x *Reason) ProtoReflect() protoreflect.Message
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) ProtoMessage ¶
func (*Result) ProtoMessage()
func (*Result) ProtoReflect ¶
func (x *Result) ProtoReflect() protoreflect.Message
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).