Add trace to registryctl

* Add trace init to main
* Add trace for http server
* Add trace for gc
* Add env template trace

Signed-off-by: Qian Deng <dengq@vmware.com>
This commit is contained in:
Qian Deng 2021-08-27 15:54:20 +00:00
parent 879eecc926
commit 14095fb10b
5 changed files with 43 additions and 7 deletions

View File

@ -9,3 +9,22 @@ INTERNAL_TLS_CERT_PATH=/etc/harbor/ssl/registryctl.crt
{% if internal_tls.verify_client_cert %}
INTERNAL_VERIFY_CLIENT_CERT=true
{% endif %}
{% if trace.enabled %}
TRACE_ENABLED=true
TRACE_SERVICE_NAME=harbor-registryctl
TRACE_SAMPLE_RATE={{ trace.sample_rate }}
{% if trace.jaeger is defined %}
TRACE_JAEGER_ENDPOINT={{ trace.jaeger.endpoint if trace.jaeger.endpoint else '' }}
TRACE_JAEGER_USERNAME={{ trace.jaeger.username if trace.jaeger.username else '' }}
TRACE_JAEGER_PASSWORD={{ trace.jaeger.password if trace.jaeger.password else '' }}
TRACE_JAEGER_AGENT_HOSTNAME={{ trace.jaeger.agent_host if trace.jaeger.agent_host else '' }}
TRACE_JAEGER_AGENT_PORT={{ trace.jaeger.agent_port if trace.jaeger.agent_port else '' }}
{% endif %}
{%if trace.otel is defined %}
TRACE_OTEL_ENDPOINT={{ trace.otel.endpoint if trace.otel.endpoint else '' }}
TRACE_OTEL_URL_PATH={{ trace.otel.url_path if trace.otel.url_path else '' }}
TRACE_OTEL_COMPRESSION={{ trace.otel.compression if trace.otel.compression else '' }}
TRACE_OTEL_TIMEOUT={{ trace.otel.timeout }}
TRACE_OTEL_INSECURE={{ trace.otel.insecure if trace.otel.insecure else '' }}
{% endif %}
{% endif %}

View File

@ -1,4 +1,4 @@
import os, shutil
import os
from g import config_dir, templates_dir, DEFAULT_GID, DEFAULT_UID
from utils.misc import prepare_dir

View File

@ -23,6 +23,7 @@ import (
common_http "github.com/goharbor/harbor/src/common/http"
"github.com/goharbor/harbor/src/common/http/modifier/auth"
"github.com/goharbor/harbor/src/common/utils"
"github.com/goharbor/harbor/src/lib/errors"
)
// const definition

View File

@ -18,10 +18,12 @@ import (
"net/http"
"os"
gorilla_handlers "github.com/gorilla/handlers"
"github.com/goharbor/harbor/src/lib/log"
tracelib "github.com/goharbor/harbor/src/lib/trace"
"github.com/goharbor/harbor/src/registryctl/auth"
"github.com/goharbor/harbor/src/registryctl/config"
gorilla_handlers "github.com/gorilla/handlers"
)
// NewHandlerChain returns a gorilla router which is wrapped by authenticate handler
@ -36,6 +38,9 @@ func NewHandlerChain(conf config.Configuration) http.Handler {
}
h = newAuthHandler(auth.NewSecretHandler(secrets), h, insecureAPIs)
h = gorilla_handlers.LoggingHandler(os.Stdout, h)
if tracelib.Enabled() {
h = tracelib.NewHandler(h, "serve-http")
}
return h
}

View File

@ -15,15 +15,11 @@
package main
import (
"context"
"crypto/tls"
"flag"
"net/http"
common_http "github.com/goharbor/harbor/src/common/http"
"github.com/goharbor/harbor/src/lib/log"
"github.com/goharbor/harbor/src/registryctl/config"
"github.com/goharbor/harbor/src/registryctl/handlers"
_ "github.com/docker/distribution/registry/storage/driver/azure"
_ "github.com/docker/distribution/registry/storage/driver/filesystem"
_ "github.com/docker/distribution/registry/storage/driver/gcs"
@ -33,6 +29,12 @@ import (
_ "github.com/docker/distribution/registry/storage/driver/oss"
_ "github.com/docker/distribution/registry/storage/driver/s3-aws"
_ "github.com/docker/distribution/registry/storage/driver/swift"
common_http "github.com/goharbor/harbor/src/common/http"
"github.com/goharbor/harbor/src/lib/log"
tracelib "github.com/goharbor/harbor/src/lib/trace"
"github.com/goharbor/harbor/src/registryctl/config"
"github.com/goharbor/harbor/src/registryctl/handlers"
)
// RegistryCtl for registry controller
@ -78,6 +80,15 @@ func main() {
log.Fatalf("Failed to load configurations with error: %s\n", err)
}
if tracelib.Enabled() {
tp := tracelib.InitGlobalTracer(context.Background())
defer func() {
if err := tp.Shutdown(context.Background()); err != nil {
log.Errorf("Error shutting down tracer provider: %v", err)
}
}()
}
regCtl := &RegistryCtl{
ServerConf: *config.DefaultConfig,
Handler: handlers.NewHandlerChain(*config.DefaultConfig),