Compare commits

...

8 Commits

Author SHA1 Message Date
3ace7657dc codec: RawMessage Marshal fix
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-09-10 10:43:45 +03:00
53b40617e2 fixup util/xpool
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-09-04 23:06:40 +03:00
1a9236caad update meter options
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-09-04 22:41:10 +03:00
6c68d39081 errors: add RFC9457 problem type
closes #297

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-08-01 01:06:02 +03:00
35e62fbeb0 tracer: add default context attr funcs option
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-07-06 00:09:27 +03:00
00b3ceb468 smeconv: fix naming
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-07-04 14:56:48 +03:00
7dc8f088c9 Merge pull request 'fix impl interface' (#346) from devstigneev/micro:fix_impl_mevent into v3
Reviewed-on: #346
2024-07-01 12:26:53 +03:00
c65afcea1b fix impl interface
Some checks failed
lint / lint (pull_request) Has been cancelled
pr / test (pull_request) Has been cancelled
2024-07-01 09:47:51 +03:00
11 changed files with 65 additions and 17 deletions

View File

@@ -373,6 +373,10 @@ func (m *memoryEvent) SetError(err error) {
m.err = err m.err = err
} }
func (m *memoryEvent) Context() context.Context {
return m.opts.Context
}
func (m *memorySubscriber) Options() broker.SubscribeOptions { func (m *memorySubscriber) Options() broker.SubscribeOptions {
return m.opts return m.opts
} }

View File

@@ -93,6 +93,8 @@ type RawMessage []byte
func (m *RawMessage) MarshalJSON() ([]byte, error) { func (m *RawMessage) MarshalJSON() ([]byte, error) {
if m == nil { if m == nil {
return []byte("null"), nil return []byte("null"), nil
} else if len(*m) == 0 {
return []byte("null"), nil
} }
return *m, nil return *m, nil
} }

View File

@@ -44,6 +44,20 @@ var (
ErrGatewayTimeout = &Error{Code: 504} ErrGatewayTimeout = &Error{Code: 504}
) )
const ProblemContentType = "application/problem+json"
type Problem struct {
Type string `json:"type,omitempty"`
Title string `json:"title,omitempty"`
Detail string `json:"detail,omitempty"`
Instance string `json:"instance,omitempty"`
Errors []struct {
Title string `json:"title,omitempty"`
Detail string `json:"detail,omitempty"`
} `json:"errors,omitempty"`
Status int `json:"status,omitempty"`
}
// Error type // Error type
type Error struct { type Error struct {
// ID holds error id or service, usually someting like my_service or id // ID holds error id or service, usually someting like my_service or id

View File

@@ -1,5 +1,5 @@
// Package logger provides a log interface // Package logger provides a log interface
package logger // import "go.unistack.org/micro/v3/logger" package logger
import ( import (
"context" "context"

View File

@@ -74,7 +74,7 @@ func NewOptions(opts ...Option) Options {
return options return options
} }
// WithContextAttrFuncs appends default funcs for the context arrts filler // WithContextAttrFuncs appends default funcs for the context attrs filler
func WithContextAttrFuncs(fncs ...ContextAttrFunc) Option { func WithContextAttrFuncs(fncs ...ContextAttrFunc) Option {
return func(o *Options) { return func(o *Options) {
o.ContextAttrFuncs = append(o.ContextAttrFuncs, fncs...) o.ContextAttrFuncs = append(o.ContextAttrFuncs, fncs...)
@@ -137,6 +137,13 @@ func WithName(n string) Option {
} }
} }
// WithMeter sets the meter
func WithMeter(m meter.Meter) Option {
return func(o *Options) {
o.Meter = m
}
}
// WithTimeFunc sets the func to obtain current time // WithTimeFunc sets the func to obtain current time
func WithTimeFunc(fn func() time.Time) Option { func WithTimeFunc(fn func() time.Time) Option {
return func(o *Options) { return func(o *Options) {

View File

@@ -305,6 +305,10 @@ func (t *tunEvent) SetError(err error) {
t.err = err t.err = err
} }
func (t *tunEvent) Context() context.Context {
return context.TODO()
}
// NewBroker returns new tunnel broker // NewBroker returns new tunnel broker
func NewBroker(opts ...broker.Option) (broker.Broker, error) { func NewBroker(opts ...broker.Option) (broker.Broker, error) {
options := broker.NewOptions(opts...) options := broker.NewOptions(opts...)

View File

@@ -1,12 +0,0 @@
package semconv
var (
// CacheRequestDurationSeconds specifies meter metric name
CacheRequestDurationSeconds = "cache_request_duration_seconds"
// ClientRequestLatencyMicroseconds specifies meter metric name
CacheRequestLatencyMicroseconds = "cache_request_latency_microseconds"
// CacheRequestTotal specifies meter metric name
CacheRequestTotal = "cache_request_total"
// CacheRequestInflight specifies meter metric name
CacheRequestInflight = "cache_request_inflight"
)

12
semconv/store.go Normal file
View File

@@ -0,0 +1,12 @@
package semconv
var (
// StoreRequestDurationSeconds specifies meter metric name
StoreRequestDurationSeconds = "store_request_duration_seconds"
// ClientRequestLatencyMicroseconds specifies meter metric name
StoreRequestLatencyMicroseconds = "store_request_latency_microseconds"
// StoreRequestTotal specifies meter metric name
StoreRequestTotal = "store_request_total"
// StoreRequestInflight specifies meter metric name
StoreRequestInflight = "store_request_inflight"
)

View File

@@ -140,6 +140,8 @@ type Options struct {
Logger logger.Logger Logger logger.Logger
// Name of the tracer // Name of the tracer
Name string Name string
// ContextAttrFuncs contains funcs that provides tracing
ContextAttrFuncs []ContextAttrFunc
} }
// Option func signature // Option func signature
@@ -176,8 +178,9 @@ func NewSpanOptions(opts ...SpanOption) SpanOptions {
// NewOptions returns default options // NewOptions returns default options
func NewOptions(opts ...Option) Options { func NewOptions(opts ...Option) Options {
options := Options{ options := Options{
Logger: logger.DefaultLogger, Logger: logger.DefaultLogger,
Context: context.Background(), Context: context.Background(),
ContextAttrFuncs: DefaultContextAttrFuncs,
} }
for _, o := range opts { for _, o := range opts {
o(&options) o(&options)

View File

@@ -21,8 +21,11 @@ var (
"HealthService.Ready", "HealthService.Ready",
"HealthService.Version", "HealthService.Version",
} }
DefaultContextAttrFuncs []ContextAttrFunc
) )
type ContextAttrFunc func(ctx context.Context) []interface{}
func init() { func init() {
logger.DefaultContextAttrFuncs = append(logger.DefaultContextAttrFuncs, logger.DefaultContextAttrFuncs = append(logger.DefaultContextAttrFuncs,
func(ctx context.Context) []interface{} { func(ctx context.Context) []interface{} {

View File

@@ -1,6 +1,9 @@
package pool package pool
import "sync" import (
"bytes"
"sync"
)
type Pool[T any] struct { type Pool[T any] struct {
p *sync.Pool p *sync.Pool
@@ -23,3 +26,11 @@ func (p Pool[T]) Get() T {
func (p Pool[T]) Put(t T) { func (p Pool[T]) Put(t T) {
p.p.Put(t) p.p.Put(t)
} }
func NewBytePool(size int) Pool[[]byte] {
return NewPool(func() []byte { return make([]byte, size) })
}
func NewBytesPool() Pool[*bytes.Buffer] {
return NewPool(func() *bytes.Buffer { return bytes.NewBuffer(nil) })
}