Skip to content

Commit

Permalink
TRANSFER-852: Make metering and runtime extendable
Browse files Browse the repository at this point in the history
  • Loading branch information
laskoviymishka committed Sep 6, 2024
1 parent efe84f3 commit 4abe595
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
9 changes: 9 additions & 0 deletions library/go/core/log/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const (
FieldTypeContext
// FieldTypeLazyCall wraps function to lazy evaluate it after log level confirm
FieldTypeLazyCall
// FieldTypeStringer is for fmt.Stringer
FieldTypeStringer

fieldTypeLast // service type for testing purposes
)
Expand Down Expand Up @@ -166,6 +168,8 @@ func (f Field) Any() interface{} {
return f.Interface()
case FieldTypeLazyCall:
return f.Interface()
case FieldTypeStringer:
return f.Interface()
default:
// For when new field type is not added to this func
panic(fmt.Sprintf("unknown field type: %d", f.Type()))
Expand All @@ -182,6 +186,11 @@ func String(key, value string) Field {
return Field{key: key, ftype: FieldTypeString, string: value}
}

// Stringer constructs field from fmt.Stringer interface
func Stringer(key string, value fmt.Stringer) Field {
return Field{key: key, ftype: FieldTypeStringer, iface: value}
}

// Sprintf constructs field of string type with formatting
func Sprintf(key, format string, args ...interface{}) Field {
return Field{key: key, ftype: FieldTypeString, string: fmt.Sprintf(format, args...)}
Expand Down
2 changes: 2 additions & 0 deletions library/go/core/log/zap/zapify.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ func zapifyField(field log.Field) zap.Field {
return zap.Reflect(field.Key(), field.Interface())
case log.FieldTypeByteString:
return zap.ByteString(field.Key(), field.Binary())
case log.FieldTypeStringer:
return zap.Stringer(field.Key(), field.Interface().(fmt.Stringer))
case log.FieldTypeContext:
return Context(field.Interface().(context.Context))
case log.FieldTypeLazyCall:
Expand Down
6 changes: 4 additions & 2 deletions transfer_manager/go/pkg/abstract/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const (
)

type Runtime interface {
isRuntime()
NeedRestart(runtime Runtime) bool
WithDefaults()
Validate() error
Expand All @@ -47,6 +46,10 @@ func NewRuntime(runtime RuntimeType, runtimeSpec string) (Runtime, error) {
}
}

func RegisterRuntime(r RuntimeType, f func(spec string) (Runtime, error)) {
knownRuntimes[r] = f
}

// Parallelism params
type ShardUploadParams struct {
JobCount int //Workers count
Expand All @@ -65,7 +68,6 @@ func DefaultShardUploadParams() *ShardUploadParams {
}

type ShardingTaskRuntime interface {
isShardingEnabled()
WorkersNum() int
ThreadsNumPerWorker() int
CurrentJobIndex() int
Expand Down
1 change: 0 additions & 1 deletion transfer_manager/go/pkg/metering/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ type Metric interface {
}

type MetricState interface {
isMetricState()
Serialize(baseOpts *MeteringOpts) (map[MetricSchema][]string, error)
}

Expand Down

0 comments on commit 4abe595

Please sign in to comment.