Migrate frontend to new service tracing setup.
This alters the frontend to use the new service tracing setup.
This commit is contained in:
+11
-2
@@ -21,6 +21,7 @@ package runtime
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-micro.dev/v4/registry"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
// Option defines a single option function.
|
||||
@@ -28,8 +29,9 @@ type Option func(o *Options)
|
||||
|
||||
// Options defines the available options for this package.
|
||||
type Options struct {
|
||||
Logger *zerolog.Logger
|
||||
Registry registry.Registry
|
||||
Logger *zerolog.Logger
|
||||
Registry registry.Registry
|
||||
TraceProvider trace.TracerProvider
|
||||
}
|
||||
|
||||
// newOptions initializes the available default options.
|
||||
@@ -56,3 +58,10 @@ func WithRegistry(r registry.Registry) Option {
|
||||
o.Registry = r
|
||||
}
|
||||
}
|
||||
|
||||
// WithTraceProvider provides a function to set the trace provider.
|
||||
func WithTraceProvider(tp trace.TracerProvider) Option {
|
||||
return func(o *Options) {
|
||||
o.TraceProvider = tp
|
||||
}
|
||||
}
|
||||
|
||||
+14
-4
@@ -58,7 +58,7 @@ func RunWithOptions(mainConf map[string]interface{}, pidFile string, opts ...Opt
|
||||
panic(err)
|
||||
}
|
||||
|
||||
run(mainConf, coreConf, options.Logger, pidFile)
|
||||
run(mainConf, coreConf, options.Logger, options.TraceProvider, pidFile)
|
||||
}
|
||||
|
||||
type coreConf struct {
|
||||
@@ -74,11 +74,21 @@ type coreConf struct {
|
||||
TracingService string `mapstructure:"tracing_service"`
|
||||
}
|
||||
|
||||
func run(mainConf map[string]interface{}, coreConf *coreConf, logger *zerolog.Logger, filename string) {
|
||||
func run(
|
||||
mainConf map[string]interface{},
|
||||
coreConf *coreConf,
|
||||
logger *zerolog.Logger,
|
||||
tp trace.TracerProvider,
|
||||
filename string,
|
||||
) {
|
||||
host, _ := os.Hostname()
|
||||
logger.Info().Msgf("host info: %s", host)
|
||||
|
||||
tp := initTracing(coreConf)
|
||||
// Only initialise tracing if we didn't get a tracer provider.
|
||||
if tp == nil {
|
||||
logger.Debug().Msg("No pre-existing tracer given, initializing tracing")
|
||||
tp = initTracing(coreConf)
|
||||
}
|
||||
initCPUCount(coreConf, logger)
|
||||
|
||||
servers := initServers(mainConf, logger, tp)
|
||||
@@ -241,7 +251,7 @@ func getWriter(out string) (io.Writer, error) {
|
||||
return os.Stdout, nil
|
||||
}
|
||||
|
||||
fd, err := os.OpenFile(out, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
fd, err := os.OpenFile(out, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "error creating log file: "+out)
|
||||
return nil, err
|
||||
|
||||
Generated
Vendored
+3
-1
@@ -662,13 +662,15 @@ func (s *service) CreateContainer(ctx context.Context, req *provider.CreateConta
|
||||
|
||||
func (s *service) TouchFile(ctx context.Context, req *provider.TouchFileRequest) (*provider.TouchFileResponse, error) {
|
||||
// FIXME these should be part of the TouchFileRequest object
|
||||
var mtime string
|
||||
if req.Opaque != nil {
|
||||
if e, ok := req.Opaque.Map["lockid"]; ok && e.Decoder == "plain" {
|
||||
ctx = ctxpkg.ContextSetLockID(ctx, string(e.Value))
|
||||
}
|
||||
mtime = utils.ReadPlainFromOpaque(req.Opaque, "X-OC-Mtime")
|
||||
}
|
||||
|
||||
err := s.storage.TouchFile(ctx, req.Ref, utils.ExistsInOpaque(req.Opaque, "markprocessing"))
|
||||
err := s.storage.TouchFile(ctx, req.Ref, utils.ExistsInOpaque(req.Opaque, "markprocessing"), mtime)
|
||||
|
||||
return &provider.TouchFileResponse{
|
||||
Status: status.NewStatusFromErrType(ctx, "touch file", err),
|
||||
|
||||
+13
-23
@@ -154,9 +154,17 @@ func (s *svc) handlePut(ctx context.Context, w http.ResponseWriter, r *http.Requ
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
opaque := &typespb.Opaque{}
|
||||
if mtime := r.Header.Get(net.HeaderOCMtime); mtime != "" {
|
||||
utils.AppendPlainToOpaque(opaque, net.HeaderOCMtime, mtime)
|
||||
|
||||
// TODO: find a way to check if the storage really accepted the value
|
||||
w.Header().Set(net.HeaderOCMtime, "accepted")
|
||||
}
|
||||
if length == 0 {
|
||||
tfRes, err := client.TouchFile(ctx, &provider.TouchFileRequest{
|
||||
Ref: ref,
|
||||
Opaque: opaque,
|
||||
Ref: ref,
|
||||
})
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error sending grpc touch file request")
|
||||
@@ -191,22 +199,7 @@ func (s *svc) handlePut(ctx context.Context, w http.ResponseWriter, r *http.Requ
|
||||
return
|
||||
}
|
||||
|
||||
opaqueMap := map[string]*typespb.OpaqueEntry{
|
||||
net.HeaderUploadLength: {
|
||||
Decoder: "plain",
|
||||
Value: []byte(strconv.FormatInt(length, 10)),
|
||||
},
|
||||
}
|
||||
|
||||
if mtime := r.Header.Get(net.HeaderOCMtime); mtime != "" {
|
||||
opaqueMap[net.HeaderOCMtime] = &typespb.OpaqueEntry{
|
||||
Decoder: "plain",
|
||||
Value: []byte(mtime),
|
||||
}
|
||||
|
||||
// TODO: find a way to check if the storage really accepted the value
|
||||
w.Header().Set(net.HeaderOCMtime, "accepted")
|
||||
}
|
||||
utils.AppendPlainToOpaque(opaque, net.HeaderUploadLength, strconv.FormatInt(length, 10))
|
||||
|
||||
// curl -X PUT https://demo.owncloud.com/remote.php/webdav/testcs.bin -u demo:demo -d '123' -v -H 'OC-Checksum: SHA1:40bd001563085fc35165329ea1ff5c5ecbdbbeef'
|
||||
|
||||
@@ -231,16 +224,13 @@ func (s *svc) handlePut(ctx context.Context, w http.ResponseWriter, r *http.Requ
|
||||
// we do not check the algorithm here, because it might depend on the storage
|
||||
if len(cparts) == 2 {
|
||||
// Translate into TUS style Upload-Checksum header
|
||||
opaqueMap[net.HeaderUploadChecksum] = &typespb.OpaqueEntry{
|
||||
Decoder: "plain",
|
||||
// algorithm is always lowercase, checksum is separated by space
|
||||
Value: []byte(strings.ToLower(cparts[0]) + " " + cparts[1]),
|
||||
}
|
||||
// algorithm is always lowercase, checksum is separated by space
|
||||
utils.AppendPlainToOpaque(opaque, net.HeaderUploadChecksum, strings.ToLower(cparts[0])+" "+cparts[1])
|
||||
}
|
||||
|
||||
uReq := &provider.InitiateFileUploadRequest{
|
||||
Ref: ref,
|
||||
Opaque: &typespb.Opaque{Map: opaqueMap},
|
||||
Opaque: opaque,
|
||||
}
|
||||
if ifMatch := r.Header.Get(net.HeaderIfMatch); ifMatch != "" {
|
||||
uReq.Options = &provider.InitiateFileUploadRequest_IfMatch{IfMatch: ifMatch}
|
||||
|
||||
+1
-1
@@ -165,7 +165,7 @@ func (fs *cephfs) CreateDir(ctx context.Context, ref *provider.Reference) error
|
||||
}
|
||||
|
||||
// TouchFile as defined in the storage.FS interface
|
||||
func (fs *cephfs) TouchFile(ctx context.Context, ref *provider.Reference, markprocessing bool) error {
|
||||
func (fs *cephfs) TouchFile(ctx context.Context, ref *provider.Reference, markprocessing bool, mtime string) error {
|
||||
return fmt.Errorf("unimplemented: TouchFile")
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -266,7 +266,7 @@ func (nc *StorageDriver) CreateDir(ctx context.Context, ref *provider.Reference)
|
||||
}
|
||||
|
||||
// TouchFile as defined in the storage.FS interface
|
||||
func (nc *StorageDriver) TouchFile(ctx context.Context, ref *provider.Reference, markprocessing bool) error {
|
||||
func (nc *StorageDriver) TouchFile(ctx context.Context, ref *provider.Reference, markprocessing bool, mtime string) error {
|
||||
return fmt.Errorf("unimplemented: TouchFile")
|
||||
}
|
||||
|
||||
|
||||
+14
-4
@@ -794,7 +794,7 @@ func (fs *owncloudsqlfs) CreateDir(ctx context.Context, ref *provider.Reference)
|
||||
}
|
||||
|
||||
// TouchFile as defined in the storage.FS interface
|
||||
func (fs *owncloudsqlfs) TouchFile(ctx context.Context, ref *provider.Reference, markprocessing bool) error {
|
||||
func (fs *owncloudsqlfs) TouchFile(ctx context.Context, ref *provider.Reference, markprocessing bool, mtime string) error {
|
||||
ip, err := fs.resolve(ctx, ref)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -830,15 +830,25 @@ func (fs *owncloudsqlfs) TouchFile(ctx context.Context, ref *provider.Reference,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mtime := time.Now().Unix()
|
||||
storageMtime := time.Now().Unix()
|
||||
mt := storageMtime
|
||||
if mtime != "" {
|
||||
t, err := strconv.Atoi(mtime)
|
||||
if err != nil {
|
||||
log.Info().
|
||||
Str("owncloudsql", ip).
|
||||
Msg("error mtime conversion. mtine set to system time")
|
||||
}
|
||||
mt = time.Unix(int64(t), 0).Unix()
|
||||
}
|
||||
|
||||
data := map[string]interface{}{
|
||||
"path": fs.toDatabasePath(ip),
|
||||
"etag": calcEtag(ctx, fi),
|
||||
"mimetype": mime.Detect(false, ip),
|
||||
"permissions": int(conversions.RoleFromResourcePermissions(parentPerms, false).OCSPermissions()), // inherit permissions of parent
|
||||
"mtime": mtime,
|
||||
"storage_mtime": mtime,
|
||||
"mtime": mt,
|
||||
"storage_mtime": storageMtime,
|
||||
}
|
||||
storageID, err := fs.getStorage(ctx, ip)
|
||||
if err != nil {
|
||||
|
||||
+1
-1
@@ -348,7 +348,7 @@ func (fs *s3FS) CreateDir(ctx context.Context, ref *provider.Reference) error {
|
||||
}
|
||||
|
||||
// TouchFile as defined in the storage.FS interface
|
||||
func (fs *s3FS) TouchFile(ctx context.Context, ref *provider.Reference, markprocessing bool) error {
|
||||
func (fs *s3FS) TouchFile(ctx context.Context, ref *provider.Reference, markprocessing bool, mtime string) error {
|
||||
return fmt.Errorf("unimplemented: TouchFile")
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ type FS interface {
|
||||
GetHome(ctx context.Context) (string, error)
|
||||
CreateHome(ctx context.Context) error
|
||||
CreateDir(ctx context.Context, ref *provider.Reference) error
|
||||
TouchFile(ctx context.Context, ref *provider.Reference, markprocessing bool) error
|
||||
TouchFile(ctx context.Context, ref *provider.Reference, markprocessing bool, mtime string) error
|
||||
Delete(ctx context.Context, ref *provider.Reference) error
|
||||
Move(ctx context.Context, oldRef, newRef *provider.Reference) error
|
||||
GetMD(ctx context.Context, ref *provider.Reference, mdKeys, fieldMask []string) (*provider.ResourceInfo, error)
|
||||
|
||||
+3
-3
@@ -76,7 +76,7 @@ type Tree interface {
|
||||
ListFolder(ctx context.Context, node *node.Node) ([]*node.Node, error)
|
||||
// CreateHome(owner *userpb.UserId) (n *node.Node, err error)
|
||||
CreateDir(ctx context.Context, node *node.Node) (err error)
|
||||
TouchFile(ctx context.Context, node *node.Node, markprocessing bool) error
|
||||
TouchFile(ctx context.Context, node *node.Node, markprocessing bool, mtime string) error
|
||||
// CreateReference(ctx context.Context, node *node.Node, targetURI *url.URL) error
|
||||
Move(ctx context.Context, oldNode *node.Node, newNode *node.Node) (err error)
|
||||
Delete(ctx context.Context, node *node.Node) (err error)
|
||||
@@ -616,7 +616,7 @@ func (fs *Decomposedfs) CreateDir(ctx context.Context, ref *provider.Reference)
|
||||
}
|
||||
|
||||
// TouchFile as defined in the storage.FS interface
|
||||
func (fs *Decomposedfs) TouchFile(ctx context.Context, ref *provider.Reference, markprocessing bool) error {
|
||||
func (fs *Decomposedfs) TouchFile(ctx context.Context, ref *provider.Reference, markprocessing bool, mtime string) error {
|
||||
parentRef := &provider.Reference{
|
||||
ResourceId: ref.ResourceId,
|
||||
Path: path.Dir(ref.Path),
|
||||
@@ -655,7 +655,7 @@ func (fs *Decomposedfs) TouchFile(ctx context.Context, ref *provider.Reference,
|
||||
if err := n.CheckLock(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return fs.tp.TouchFile(ctx, n, markprocessing)
|
||||
return fs.tp.TouchFile(ctx, n, markprocessing, mtime)
|
||||
}
|
||||
|
||||
// CreateReference creates a reference as a node folder with the target stored in extended attributes
|
||||
|
||||
+6
-1
@@ -128,7 +128,7 @@ func (t *Tree) GetMD(ctx context.Context, n *node.Node) (os.FileInfo, error) {
|
||||
}
|
||||
|
||||
// TouchFile creates a new empty file
|
||||
func (t *Tree) TouchFile(ctx context.Context, n *node.Node, markprocessing bool) error {
|
||||
func (t *Tree) TouchFile(ctx context.Context, n *node.Node, markprocessing bool, mtime string) error {
|
||||
if n.Exists {
|
||||
if markprocessing {
|
||||
return n.SetXattr(prefixes.StatusPrefix, []byte(node.ProcessingStatus))
|
||||
@@ -155,6 +155,11 @@ func (t *Tree) TouchFile(ctx context.Context, n *node.Node, markprocessing bool)
|
||||
if markprocessing {
|
||||
attributes[prefixes.StatusPrefix] = []byte(node.ProcessingStatus)
|
||||
}
|
||||
if mtime != "" {
|
||||
if err := n.SetMtimeString(mtime); err != nil {
|
||||
return errors.Wrap(err, "Decomposedfs: could not set mtime")
|
||||
}
|
||||
}
|
||||
err = n.SetXattrs(attributes, true)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
+2
-3
@@ -21,6 +21,7 @@ package eosfs
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
b64 "encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -33,8 +34,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
b64 "encoding/base64"
|
||||
|
||||
"github.com/bluele/gcache"
|
||||
grouppb "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1"
|
||||
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
@@ -1673,7 +1672,7 @@ func (fs *eosfs) CreateDir(ctx context.Context, ref *provider.Reference) error {
|
||||
}
|
||||
|
||||
// TouchFile as defined in the storage.FS interface
|
||||
func (fs *eosfs) TouchFile(ctx context.Context, ref *provider.Reference, _ bool) error {
|
||||
func (fs *eosfs) TouchFile(ctx context.Context, ref *provider.Reference, _ bool, _ string) error {
|
||||
log := appctx.GetLogger(ctx)
|
||||
|
||||
fn, auth, err := fs.resolveRefAndGetAuth(ctx, ref)
|
||||
|
||||
+1
-1
@@ -806,7 +806,7 @@ func (fs *localfs) CreateDir(ctx context.Context, ref *provider.Reference) error
|
||||
}
|
||||
|
||||
// TouchFile as defined in the storage.FS interface
|
||||
func (fs *localfs) TouchFile(ctx context.Context, ref *provider.Reference, _ bool) error {
|
||||
func (fs *localfs) TouchFile(ctx context.Context, ref *provider.Reference, _ bool, _ string) error {
|
||||
return fmt.Errorf("unimplemented: TouchFile")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user