Merge branch 'master' into update-bridge-docs

This commit is contained in:
A.Unger
2021-09-29 12:09:29 +02:00
511 changed files with 12687 additions and 17566 deletions
+1 -1
View File
@@ -4,9 +4,9 @@ import (
"fmt"
"net/http"
"github.com/micro/cli/v2"
"github.com/owncloud/ocis/thumbnails/pkg/config"
"github.com/owncloud/ocis/thumbnails/pkg/flagset"
"github.com/urfave/cli/v2"
)
// Health is the entrypoint for the health command.
+1 -1
View File
@@ -7,13 +7,13 @@ import (
"github.com/owncloud/ocis/ocis-pkg/sync"
"github.com/micro/cli/v2"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/thumbnails/pkg/config"
"github.com/owncloud/ocis/thumbnails/pkg/version"
"github.com/spf13/viper"
"github.com/thejerf/suture/v4"
"github.com/urfave/cli/v2"
)
// Execute is the entry point for the ocis-thumbnails command.
+2 -2
View File
@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"github.com/micro/cli/v2"
"github.com/oklog/run"
"github.com/owncloud/ocis/ocis-pkg/sync"
"github.com/owncloud/ocis/thumbnails/pkg/config"
@@ -13,6 +12,7 @@ import (
"github.com/owncloud/ocis/thumbnails/pkg/server/debug"
"github.com/owncloud/ocis/thumbnails/pkg/server/grpc"
"github.com/owncloud/ocis/thumbnails/pkg/tracing"
"github.com/urfave/cli/v2"
)
// Server is the entrypoint for the server command.
@@ -38,7 +38,7 @@ func Server(cfg *config.Config) *cli.Command {
},
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)
if err := tracing.Configure(cfg, logger); err != nil {
if err := tracing.Configure(cfg); err != nil {
return err
}
+1 -1
View File
@@ -6,10 +6,10 @@ import (
"github.com/owncloud/ocis/ocis-pkg/registry"
"github.com/micro/cli/v2"
tw "github.com/olekukonko/tablewriter"
"github.com/owncloud/ocis/thumbnails/pkg/config"
"github.com/owncloud/ocis/thumbnails/pkg/flagset"
"github.com/urfave/cli/v2"
)
// PrintVersion prints the service versions of all running instances.
+5 -5
View File
@@ -3,8 +3,8 @@ package flagset
import (
"github.com/owncloud/ocis/ocis-pkg/flags"
"github.com/micro/cli/v2"
"github.com/owncloud/ocis/thumbnails/pkg/config"
"github.com/urfave/cli/v2"
)
// HealthWithConfig applies cfg to the root flagset
@@ -57,28 +57,28 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
&cli.BoolFlag{
Name: "tracing-enabled",
Usage: "Enable sending traces",
EnvVars: []string{"THUMBNAILS_TRACING_ENABLED"},
EnvVars: []string{"THUMBNAILS_TRACING_ENABLED", "OCIS_TRACING_ENABLED"},
Destination: &cfg.Tracing.Enabled,
},
&cli.StringFlag{
Name: "tracing-type",
Value: flags.OverrideDefaultString(cfg.Tracing.Type, "jaeger"),
Usage: "Tracing backend type",
EnvVars: []string{"THUMBNAILS_TRACING_TYPE"},
EnvVars: []string{"THUMBNAILS_TRACING_TYPE", "OCIS_TRACING_TYPE"},
Destination: &cfg.Tracing.Type,
},
&cli.StringFlag{
Name: "tracing-endpoint",
Value: flags.OverrideDefaultString(cfg.Tracing.Endpoint, ""),
Usage: "Endpoint for the agent",
EnvVars: []string{"THUMBNAILS_TRACING_ENDPOINT"},
EnvVars: []string{"THUMBNAILS_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"},
Destination: &cfg.Tracing.Endpoint,
},
&cli.StringFlag{
Name: "tracing-collector",
Value: flags.OverrideDefaultString(cfg.Tracing.Collector, ""),
Usage: "Endpoint for the collector",
EnvVars: []string{"THUMBNAILS_TRACING_COLLECTOR"},
EnvVars: []string{"THUMBNAILS_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"},
Destination: &cfg.Tracing.Collector,
},
&cli.StringFlag{
+2 -2
View File
@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.15.2
// protoc-gen-go v1.27.1
// protoc v3.17.3
// source: thumbnails.proto
package proto
@@ -5,8 +5,8 @@ package proto
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
_ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options"
proto "google.golang.org/protobuf/proto"
math "math"
)
@@ -22,12 +22,6 @@ var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
// Reference imports to suppress errors if they are not otherwise used.
var _ api.Endpoint
var _ context.Context
@@ -42,14 +42,11 @@
"protobufAny": {
"type": "object",
"properties": {
"typeUrl": {
"@type": {
"type": "string"
},
"value": {
"type": "string",
"format": "byte"
}
}
},
"additionalProperties": {}
},
"rpcStatus": {
"type": "object",
+1 -1
View File
@@ -3,10 +3,10 @@ package grpc
import (
"context"
"github.com/micro/cli/v2"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/thumbnails/pkg/config"
"github.com/owncloud/ocis/thumbnails/pkg/metrics"
"github.com/urfave/cli/v2"
)
// Option defines a single option function.
+1
View File
@@ -47,6 +47,7 @@ func NewService(opts ...Option) grpc.Service {
)
thumbnail = svc.NewInstrument(thumbnail, options.Metrics)
thumbnail = svc.NewLogging(thumbnail, options.Logger)
thumbnail = svc.NewTracing(thumbnail)
}
_ = proto.RegisterThumbnailServiceHandler(
+17 -9
View File
@@ -3,8 +3,11 @@ package svc
import (
"context"
"go.opentelemetry.io/otel/trace"
v0proto "github.com/owncloud/ocis/thumbnails/pkg/proto/v0"
"go.opencensus.io/trace"
thumbnailsTracing "github.com/owncloud/ocis/thumbnails/pkg/tracing"
"go.opentelemetry.io/otel/attribute"
)
// NewTracing returns a service that instruments traces.
@@ -20,15 +23,20 @@ type tracing struct {
// GetThumbnail implements the ThumbnailServiceHandler interface.
func (t tracing) GetThumbnail(ctx context.Context, req *v0proto.GetThumbnailRequest, rsp *v0proto.GetThumbnailResponse) error {
ctx, span := trace.StartSpan(ctx, "Thumbnails.GetThumbnail")
defer span.End()
var span trace.Span
span.Annotate([]trace.Attribute{
trace.StringAttribute("filepath", req.Filepath),
trace.StringAttribute("thumbnail_type", req.ThumbnailType.String()),
trace.Int64Attribute("width", int64(req.Width)),
trace.Int64Attribute("height", int64(req.Height)),
}, "Execute Thumbnails.GetThumbnail handler")
if thumbnailsTracing.TraceProvider != nil {
tracer := thumbnailsTracing.TraceProvider.Tracer("thumbnails")
ctx, span = tracer.Start(ctx, "Thumbnails.GetThumbnail")
defer span.End()
span.SetAttributes(
attribute.KeyValue{Key: "filepath", Value: attribute.StringValue(req.Filepath)},
attribute.KeyValue{Key: "thumbnail_type", Value: attribute.StringValue(req.ThumbnailType.String())},
attribute.KeyValue{Key: "width", Value: attribute.IntValue(int(req.Width))},
attribute.KeyValue{Key: "height", Value: attribute.IntValue(int(req.Height))},
)
}
return t.next.GetThumbnail(ctx, req, rsp)
}
+3 -3
View File
@@ -11,12 +11,12 @@ import (
)
const (
_resolutionSeperator = "x"
_resolutionSeparator = "x"
)
// ParseResolution returns an image.Rectangle representing the resolution given as a string
func ParseResolution(s string) (image.Rectangle, error) {
parts := strings.Split(s, _resolutionSeperator)
parts := strings.Split(s, _resolutionSeparator)
if len(parts) != 2 {
return image.Rectangle{}, fmt.Errorf("failed to parse resolution: %s. Expected format <width>x<height>", s)
}
@@ -78,7 +78,7 @@ func (rs Resolutions) ClosestMatch(requested image.Rectangle, sourceSize image.R
}
// Convert diff to positive value
// Multiplying by -1 is safe since we aren't getting postive numbers here
// Multiplying by -1 is safe since we aren't getting positive numbers here
// because of the check above
absDiff := diff * -1
if absDiff < minDiff {
+12 -79
View File
@@ -1,90 +1,23 @@
package tracing
import (
"time"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/ocis-pkg/log"
pkgtrace "github.com/owncloud/ocis/ocis-pkg/tracing"
"github.com/owncloud/ocis/thumbnails/pkg/config"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
"go.opentelemetry.io/otel/trace"
)
func Configure(cfg *config.Config, logger log.Logger) error {
var (
// TraceProvider is the global trace provider for the thumbnails service.
TraceProvider = trace.NewNoopTracerProvider()
)
func Configure(cfg *config.Config) error {
var err error
if cfg.Tracing.Enabled {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err
}
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
Process: jaeger.Process{
ServiceName: cfg.Tracing.Service,
},
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, "thumbnails", cfg.Tracing.Type); err != nil {
return err
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
return nil
}