From f59e2e3fa472b436834fee831a072dc689bf1b6a Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Fri, 20 Dec 2024 10:19:02 -0800 Subject: [PATCH] Move shared services and host to components This change moves the shared host package and diagnostics services to the new `pkg/components` folder. Also simplifies and improves consistency. As part of this work, I made changes to the configuration file for consistency. Each of these diagnostics features now has a dedicated on/off switch. Where a service name is required, it is now specific in configuration rather than hardcoded in the code. Also made the names of configuration files consistent and reflective of their scenario. All of the configuration files used for development reflect the 'dev' terminology. All of the configuration files used for self-hosted Radius (in Kubernetes) reflect the 'self-hosted' terminology. Signed-off-by: Ryan Nowak --- .vscode/launch.json | 18 ------ ...f-hosted.yaml => applications-rp-dev.yaml} | 8 ++- cmd/applications-rp/cmd/root.go | 46 +++++++------- cmd/applications-rp/radius-dev.yaml | 43 ------------- cmd/controller/cmd/root.go | 14 +++-- ...r-self-hosted.yaml => controller-dev.yaml} | 10 ++- cmd/dynamic-rp/cmd/root.go | 2 +- cmd/dynamic-rp/dynamicrp-dev.yaml | 10 ++- cmd/rad/cmd/root.go | 26 ++++++-- cmd/ucpd/cmd/root.go | 4 +- cmd/ucpd/ucp-dev.yaml | 6 +- .../templates/controller/configmaps.yaml | 4 +- .../templates/dynamic-rp/configmaps.yaml | 4 +- deploy/Chart/templates/rp/configmaps.yaml | 6 +- deploy/Chart/templates/ucp/configmaps.yaml | 6 +- .../configSettings.md | 63 +------------------ .../statusmanager/statusmanager.go | 4 +- pkg/armrpc/asyncoperation/worker/worker.go | 4 +- pkg/armrpc/hostoptions/env.go | 29 ++------- pkg/armrpc/hostoptions/providerconfig.go | 34 +++++----- pkg/{ucp => components}/hosting/hosting.go | 0 .../hosting/hosting_test.go | 0 pkg/{ucp => components}/hosting/run.go | 0 pkg/{ => components}/metrics/README.md | 0 .../metrics/asyncoperationmetrics.go | 0 pkg/{ => components}/metrics/metrics.go | 0 .../metrics/metricsservice}/options.go | 24 ++++--- .../metricsservice}/prometheusexporter.go | 4 +- .../metrics/metricsservice}/service.go | 19 ++---- .../metrics/recipeenginemetrics.go | 0 pkg/{ => components}/metrics/types.go | 0 .../profiler/profilerservice}/service.go | 19 +++--- pkg/components/testhost/host.go | 2 +- pkg/{ => components}/trace/doc.go | 0 .../trace/traceservice}/options.go | 4 +- .../trace/traceservice/service.go} | 16 ++--- pkg/{ => components}/trace/util.go | 0 pkg/{ => components}/trace/util_test.go | 0 pkg/controller/service.go | 6 +- pkg/dynamicrp/config.go | 12 ++-- pkg/dynamicrp/server/server.go | 22 +++---- pkg/metrics/service/hostoptions.go | 35 ----------- .../processors/resourceclient.go | 2 +- pkg/profiler/provider/options.go | 23 ------- pkg/profiler/service/hostoptions.go | 34 ---------- pkg/recipes/driver/bicep.go | 2 +- pkg/recipes/engine/engine.go | 2 +- pkg/recipes/terraform/execute.go | 2 +- pkg/recipes/terraform/install.go | 2 +- pkg/recipes/terraform/module.go | 2 +- pkg/ucp/config.go | 12 ++-- pkg/ucp/frontend/api/server.go | 2 +- pkg/ucp/server/server.go | 28 ++++----- 53 files changed, 211 insertions(+), 404 deletions(-) rename cmd/applications-rp/{radius-self-hosted.yaml => applications-rp-dev.yaml} (91%) delete mode 100644 cmd/applications-rp/radius-dev.yaml rename cmd/controller/{controller-self-hosted.yaml => controller-dev.yaml} (70%) rename pkg/{ucp => components}/hosting/hosting.go (100%) rename pkg/{ucp => components}/hosting/hosting_test.go (100%) rename pkg/{ucp => components}/hosting/run.go (100%) rename pkg/{ => components}/metrics/README.md (100%) rename pkg/{ => components}/metrics/asyncoperationmetrics.go (100%) rename pkg/{ => components}/metrics/metrics.go (100%) rename pkg/{metrics/provider => components/metrics/metricsservice}/options.go (52%) rename pkg/{metrics/provider => components/metrics/metricsservice}/prometheusexporter.go (94%) rename pkg/{metrics/service => components/metrics/metricsservice}/service.go (81%) rename pkg/{ => components}/metrics/recipeenginemetrics.go (100%) rename pkg/{ => components}/metrics/types.go (100%) rename pkg/{profiler/service => components/profiler/profilerservice}/service.go (82%) rename pkg/{ => components}/trace/doc.go (100%) rename pkg/{trace => components/trace/traceservice}/options.go (90%) rename pkg/{trace/trace.go => components/trace/traceservice/service.go} (81%) rename pkg/{ => components}/trace/util.go (100%) rename pkg/{ => components}/trace/util_test.go (100%) delete mode 100644 pkg/metrics/service/hostoptions.go delete mode 100644 pkg/profiler/provider/options.go delete mode 100644 pkg/profiler/service/hostoptions.go diff --git a/.vscode/launch.json b/.vscode/launch.json index 899ef7aa1e..85a8aaa6fe 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -31,13 +31,6 @@ "mode": "auto", "preLaunchTask": "Build Radius (all)", "program": "${workspaceFolder}/cmd/applications-rp/main.go", - "args": [ - "--config-file", - "${workspaceFolder}/cmd/applications-rp/radius-self-hosted.yaml" - ], - "env": { - "RADIUS_ENV": "self-hosted" - } }, { "name": "Launch Dynamic RP", @@ -54,11 +47,6 @@ "mode": "auto", "preLaunchTask": "Build Radius (all)", "program": "${workspaceFolder}/cmd/ucpd/main.go", - "cwd": "${workspaceFolder}", - "args": [ - "--config-file", - "${workspaceFolder}/cmd/ucpd/ucp-dev.yaml" - ] }, { "name": "Launch Controller", @@ -67,16 +55,10 @@ "mode": "auto", "preLaunchTask": "Build Radius (all)", "program": "${workspaceFolder}/cmd/controller/main.go", - "cwd": "${workspaceFolder}", "args": [ - "--config-file", - "${workspaceFolder}/cmd/controller/controller-self-hosted.yaml", "--cert-dir", "" ], - "env": { - "RADIUS_ENV": "self-hosted" - } }, { "name": "Launch Deployment Engine", diff --git a/cmd/applications-rp/radius-self-hosted.yaml b/cmd/applications-rp/applications-rp-dev.yaml similarity index 91% rename from cmd/applications-rp/radius-self-hosted.yaml rename to cmd/applications-rp/applications-rp-dev.yaml index 121ee728d0..e2a1c7a6e6 100644 --- a/cmd/applications-rp/radius-self-hosted.yaml +++ b/cmd/applications-rp/applications-rp-dev.yaml @@ -8,7 +8,7 @@ # - Disables metrics and profiler # environment: - name: self-hosted + name: "dev" roleLocation: "global" databaseProvider: provider: "apiserver" @@ -24,8 +24,9 @@ queueProvider: secretProvider: provider: "kubernetes" metricsProvider: + enabled: false + serviceName: applications-rp prometheus: - enabled: true path: "/metrics" port: 9092 profilerProvider: @@ -49,7 +50,8 @@ logging: json: false # Tracing configuration tracerProvider: - serviceName: "applications.core" + enabled: false + serviceName: applications-rp zipkin: url: "http://localhost:9411/api/v2/spans" bicep: diff --git a/cmd/applications-rp/cmd/root.go b/cmd/applications-rp/cmd/root.go index 6e891b9f66..0a66a87cab 100644 --- a/cmd/applications-rp/cmd/root.go +++ b/cmd/applications-rp/cmd/root.go @@ -26,13 +26,13 @@ import ( "github.com/radius-project/radius/pkg/armrpc/builder" "github.com/radius-project/radius/pkg/armrpc/hostoptions" - metricsservice "github.com/radius-project/radius/pkg/metrics/service" - profilerservice "github.com/radius-project/radius/pkg/profiler/service" + "github.com/radius-project/radius/pkg/components/metrics/metricsservice" + "github.com/radius-project/radius/pkg/components/profiler/profilerservice" + "github.com/radius-project/radius/pkg/components/trace/traceservice" "github.com/radius-project/radius/pkg/recipes/controllerconfig" "github.com/radius-project/radius/pkg/server" - "github.com/radius-project/radius/pkg/trace" - "github.com/radius-project/radius/pkg/ucp/hosting" + "github.com/radius-project/radius/pkg/components/hosting" "github.com/radius-project/radius/pkg/ucp/ucplog" corerp_setup "github.com/radius-project/radius/pkg/corerp/setup" @@ -54,19 +54,6 @@ var rootCmd = &cobra.Command{ return err } - hostingSvc := []hosting.Service{} - - metricOptions := metricsservice.NewHostOptionsFromEnvironment(*options.Config) - metricOptions.Config.ServiceName = serviceName - if metricOptions.Config.Prometheus.Enabled { - hostingSvc = append(hostingSvc, metricsservice.NewService(metricOptions)) - } - - profilerOptions := profilerservice.NewHostOptionsFromEnvironment(*options.Config) - if profilerOptions.Config.Enabled { - hostingSvc = append(hostingSvc, profilerservice.NewService(profilerOptions)) - } - logger, flush, err := ucplog.NewLogger(serviceName, &options.Config.Logging) if err != nil { return err @@ -76,23 +63,32 @@ var rootCmd = &cobra.Command{ // Must set the logger before using controller-runtime. runtimelog.SetLogger(logger) + services := []hosting.Service{} + if options.Config.MetricsProvider.Enabled { + services = append(services, &metricsservice.Service{Options: &options.Config.MetricsProvider}) + } + + if options.Config.ProfilerProvider.Enabled { + services = append(services, &profilerservice.Service{Options: &options.Config.ProfilerProvider}) + } + + if options.Config.TracerProvider.Enabled { + services = append(services, &traceservice.Service{Options: &options.Config.TracerProvider}) + } + builders, err := builders(options) if err != nil { return err } - hostingSvc = append( - hostingSvc, + services = append( + services, server.NewAPIService(options, builders), server.NewAsyncWorker(options, builders), ) - tracerOpts := options.Config.TracerProvider - tracerOpts.ServiceName = serviceName - hostingSvc = append(hostingSvc, &trace.Service{Options: tracerOpts}) - host := &hosting.Host{ - Services: hostingSvc, + Services: services, } // Make the logger available to the services. @@ -107,7 +103,7 @@ var rootCmd = &cobra.Command{ func Execute() { // Let users override the configuration via `--config-file`. - rootCmd.Flags().String("config-file", fmt.Sprintf("radius-%s.yaml", hostoptions.Environment()), "The service configuration file.") + rootCmd.Flags().String("config-file", fmt.Sprintf("applications-rp-%s.yaml", hostoptions.Environment()), "The service configuration file.") cobra.CheckErr(rootCmd.ExecuteContext(context.Background())) } diff --git a/cmd/applications-rp/radius-dev.yaml b/cmd/applications-rp/radius-dev.yaml deleted file mode 100644 index c69667a7dc..0000000000 --- a/cmd/applications-rp/radius-dev.yaml +++ /dev/null @@ -1,43 +0,0 @@ -# This is an example of configuration file. -environment: - name: Dev - roleLocation: "global" -databaseProvider: - provider: "etcd" - etcd: - inmemory: true -queueProvider: - provider: inmemory - name: radius -profilerProvider: - enabled: true - port: 6060 -secretProvider: - provider: etcd - etcd: - inmemory: true -metricsProvider: - prometheus: - enabled: true - path: "/metrics" - port: 9090 -featureFlags: - - "PLACEHOLDER" -server: - host: "0.0.0.0" - port: 8080 - enableArmAuth: false -workerServer: - maxOperationConcurrency: 10 - maxOperationRetryCount: 2 -ucp: - kind: kubernetes - # Logging configuration -logging: - level: "info" - json: false -bicep: - deleteRetryCount: 20 - deleteRetryDelaySeconds: 60 -terraform: - path: "/terraform" \ No newline at end of file diff --git a/cmd/controller/cmd/root.go b/cmd/controller/cmd/root.go index 88137025c4..4ac4c42f5a 100644 --- a/cmd/controller/cmd/root.go +++ b/cmd/controller/cmd/root.go @@ -28,9 +28,9 @@ import ( "github.com/go-logr/logr" "github.com/radius-project/radius/pkg/armrpc/hostoptions" + "github.com/radius-project/radius/pkg/components/hosting" + "github.com/radius-project/radius/pkg/components/trace/traceservice" "github.com/radius-project/radius/pkg/controller" - "github.com/radius-project/radius/pkg/trace" - "github.com/radius-project/radius/pkg/ucp/hosting" "github.com/radius-project/radius/pkg/ucp/ucplog" "github.com/spf13/cobra" runtimelog "sigs.k8s.io/controller-runtime/pkg/log" @@ -62,11 +62,15 @@ var rootCmd = &cobra.Command{ logger.Info("Loaded options", "configfile", configFilePath) - host := &hosting.Host{Services: []hosting.Service{ - &trace.Service{Options: options.Config.TracerProvider}, + services := []hosting.Service{ &controller.Service{Options: options, TLSCertDir: tlsCertDir}, - }} + } + + if options.Config.TracerProvider.Enabled { + services = append(services, &traceservice.Service{Options: &options.Config.TracerProvider}) + } + host := &hosting.Host{Services: services} return hosting.RunWithInterrupts(ctx, host) }, } diff --git a/cmd/controller/controller-self-hosted.yaml b/cmd/controller/controller-dev.yaml similarity index 70% rename from cmd/controller/controller-self-hosted.yaml rename to cmd/controller/controller-dev.yaml index a3c4274dc5..b3f398d158 100644 --- a/cmd/controller/controller-self-hosted.yaml +++ b/cmd/controller/controller-dev.yaml @@ -1,14 +1,20 @@ environment: - name: Dev + name: "dev" roleLocation: "global" profilerProvider: enabled: true port: 6063 metricsProvider: + enabled: true + serviceName: "controller" prometheus: - enabled: true path: "/metrics" port: 9093 +tracerProvider: + enabled: false + serviceName: "controller" + zipkin: + url: "http://localhost:9411/api/v2/spans" server: host: "0.0.0.0" port: 8083 diff --git a/cmd/dynamic-rp/cmd/root.go b/cmd/dynamic-rp/cmd/root.go index 046ce4002d..1b5513ad7f 100644 --- a/cmd/dynamic-rp/cmd/root.go +++ b/cmd/dynamic-rp/cmd/root.go @@ -26,9 +26,9 @@ import ( runtimelog "sigs.k8s.io/controller-runtime/pkg/log" "github.com/radius-project/radius/pkg/armrpc/hostoptions" + "github.com/radius-project/radius/pkg/components/hosting" "github.com/radius-project/radius/pkg/dynamicrp" "github.com/radius-project/radius/pkg/dynamicrp/server" - "github.com/radius-project/radius/pkg/ucp/hosting" "github.com/radius-project/radius/pkg/ucp/ucplog" ) diff --git a/cmd/dynamic-rp/dynamicrp-dev.yaml b/cmd/dynamic-rp/dynamicrp-dev.yaml index 22f60a4fe7..0df8054d64 100644 --- a/cmd/dynamic-rp/dynamicrp-dev.yaml +++ b/cmd/dynamic-rp/dynamicrp-dev.yaml @@ -1,6 +1,6 @@ # This is an example of configuration file. environment: - name: Dev + name: "dev" roleLocation: "global" databaseProvider: provider: "apiserver" @@ -19,10 +19,16 @@ profilerProvider: enabled: false port: 6062 metricsProvider: + enabled: false + serviceName: "dynamic-rp" prometheus: - enabled: false path: "/metrics" port: 9092 +tracerProvider: + enabled: false + serviceName: "dynamic-rp" + zipkin: + url: "http://localhost:9411/api/v2/spans" server: host: "0.0.0.0" port: 8082 diff --git a/cmd/rad/cmd/root.go b/cmd/rad/cmd/root.go index 466c26e0b0..f81e8e78b8 100644 --- a/cmd/rad/cmd/root.go +++ b/cmd/rad/cmd/root.go @@ -82,8 +82,11 @@ import ( "github.com/radius-project/radius/pkg/cli/kubernetes/portforward" "github.com/radius-project/radius/pkg/cli/output" "github.com/radius-project/radius/pkg/cli/prompt" - "github.com/radius-project/radius/pkg/trace" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/sdk/resource" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + semconv "go.opentelemetry.io/otel/semconv/v1.17.0" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -144,9 +147,7 @@ func prettyPrintJSON(o any) (string, error) { func Execute() error { ctx := context.WithValue(context.Background(), ConfigHolderKey, ConfigHolder) - shutdown, err := trace.InitTracer(trace.Options{ - ServiceName: serviceName, - }) + shutdown, err := initTracer() if err != nil { fmt.Println("Error:", err) return err @@ -182,6 +183,23 @@ func Execute() error { return nil } +func initTracer() (func(context.Context) error, error) { + // Intialize the tracer provider + tp := sdktrace.NewTracerProvider( + sdktrace.WithSampler(sdktrace.AlwaysSample()), + sdktrace.WithResource(resource.NewWithAttributes( + semconv.SchemaURL, + semconv.ServiceNameKey.String(serviceName), + )), + ) + + // Set the tracer provider as "global" for the CLI process. + otel.SetTracerProvider(tp) + otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{})) + + return tp.Shutdown, nil +} + func init() { cobra.OnInitialize(initConfig) diff --git a/cmd/ucpd/cmd/root.go b/cmd/ucpd/cmd/root.go index 1face5384c..e108b4e9fb 100644 --- a/cmd/ucpd/cmd/root.go +++ b/cmd/ucpd/cmd/root.go @@ -26,8 +26,8 @@ import ( runtimelog "sigs.k8s.io/controller-runtime/pkg/log" "github.com/radius-project/radius/pkg/armrpc/hostoptions" + "github.com/radius-project/radius/pkg/components/hosting" "github.com/radius-project/radius/pkg/ucp" - "github.com/radius-project/radius/pkg/ucp/hosting" "github.com/radius-project/radius/pkg/ucp/server" "github.com/radius-project/radius/pkg/ucp/ucplog" ) @@ -75,6 +75,6 @@ var rootCmd = &cobra.Command{ func Execute() { // Let users override the configuration via `--config-file`. - rootCmd.Flags().String("config-file", fmt.Sprintf("radius-%s.yaml", hostoptions.Environment()), "The service configuration file.") + rootCmd.Flags().String("config-file", fmt.Sprintf("ucp-%s.yaml", hostoptions.Environment()), "The service configuration file.") cobra.CheckErr(rootCmd.ExecuteContext(context.Background())) } diff --git a/cmd/ucpd/ucp-dev.yaml b/cmd/ucpd/ucp-dev.yaml index a7561eeb7a..3bc09c4871 100644 --- a/cmd/ucpd/ucp-dev.yaml +++ b/cmd/ucpd/ucp-dev.yaml @@ -10,7 +10,7 @@ # - Disables metrics and profiler # environment: - name: Dev + name: "dev" roleLocation: "global" server: port: 9000 @@ -69,8 +69,9 @@ routing: # port is not the same as metrics configuration in radius-self-hosted.yaml # so that we can run both services in debug mode. metricsProvider: + enabled: false + serviceName: "ucp" prometheus: - enabled: false path: "/metrics" port: 9091 @@ -81,6 +82,7 @@ logging: # Tracing configuration tracerProvider: + enabled: false serviceName: "ucp" zipkin: url: "http://localhost:9411/api/v2/spans" \ No newline at end of file diff --git a/deploy/Chart/templates/controller/configmaps.yaml b/deploy/Chart/templates/controller/configmaps.yaml index 17fabbc717..281a05404e 100644 --- a/deploy/Chart/templates/controller/configmaps.yaml +++ b/deploy/Chart/templates/controller/configmaps.yaml @@ -36,8 +36,9 @@ data: kind: kubernetes metricsProvider: + enabled: true + serviceName: "controller" prometheus: - enabled: true path: "/metrics" port: 9090 @@ -50,6 +51,7 @@ data: {{- if and .Values.global.zipkin .Values.global.zipkin.url }} tracerProvider: + enabled: true serviceName: "controller" zipkin: url: {{ .Values.global.zipkin.url }} diff --git a/deploy/Chart/templates/dynamic-rp/configmaps.yaml b/deploy/Chart/templates/dynamic-rp/configmaps.yaml index 9dc3c2ddf2..231e81d2f4 100644 --- a/deploy/Chart/templates/dynamic-rp/configmaps.yaml +++ b/deploy/Chart/templates/dynamic-rp/configmaps.yaml @@ -25,8 +25,9 @@ data: context: "" namespace: "radius-system" metricsProvider: + enabled: true + serviceName: "dynamic-rp" prometheus: - enabled: true path: "/metrics" port: 9092 profilerProvider: @@ -47,6 +48,7 @@ data: json: true {{- if and .Values.global.zipkin .Values.global.zipkin.url }} tracerProvider: + enabled: true serviceName: "dynamic-rp" zipkin: url: {{ .Values.global.zipkin.url }} diff --git a/deploy/Chart/templates/rp/configmaps.yaml b/deploy/Chart/templates/rp/configmaps.yaml index 6429960c08..78aeb8ac98 100644 --- a/deploy/Chart/templates/rp/configmaps.yaml +++ b/deploy/Chart/templates/rp/configmaps.yaml @@ -25,8 +25,9 @@ data: context: "" namespace: "radius-system" metricsProvider: + enabled: true + serviceName: "applications-rp" prometheus: - enabled: true path: "/metrics" port: 9090 profilerProvider: @@ -47,7 +48,8 @@ data: json: true {{- if and .Values.global.zipkin .Values.global.zipkin.url }} tracerProvider: - serviceName: "applications.core" + enabled: true + serviceName: "applications-rp" zipkin: url: {{ .Values.global.zipkin.url }} {{- end }} diff --git a/deploy/Chart/templates/ucp/configmaps.yaml b/deploy/Chart/templates/ucp/configmaps.yaml index cc9968228c..5dcad4fae0 100644 --- a/deploy/Chart/templates/ucp/configmaps.yaml +++ b/deploy/Chart/templates/ucp/configmaps.yaml @@ -11,7 +11,7 @@ data: # Radius configuration file. # See https://github.com/radius-project/radius/blob/main/docs/contributing/contributing-code/contributing-code-control-plane/configSettings.md for more information. environment: - name: Dev + name: self-hosted roleLocation: "global" server: port: 9443 @@ -61,8 +61,9 @@ data: defaultDownstreamEndpoint: "http://dynamic-rp.radius-sytem:8082" metricsProvider: + enabled: true + serviceName: "ucp" prometheus: - enabled: true path: "/metrics" port: 9090 @@ -72,6 +73,7 @@ data: {{- if and .Values.global.zipkin .Values.global.zipkin.url }} tracerProvider: + enabled: true serviceName: "ucp" zipkin: url: {{ .Values.global.zipkin.url }} diff --git a/docs/contributing/contributing-code/contributing-code-control-plane/configSettings.md b/docs/contributing/contributing-code/contributing-code-control-plane/configSettings.md index 356140ac77..e95262fb0f 100644 --- a/docs/contributing/contributing-code/contributing-code-control-plane/configSettings.md +++ b/docs/contributing/contributing-code/contributing-code-control-plane/configSettings.md @@ -174,68 +174,7 @@ ucp: ## Example configuration files -Below are completed examples of possible configurations: - -### Applications.Core and Portable Resources' Providers -```yaml -environment: - name: self-hosted - roleLocation: "global" -databaseProvider: - provider: "apiserver" - apiserver: - context: "" - namespace: "radius-system" -queueProvider: - provider: "apiserver" - name: "radius" - apiserver: - context: "" - namespace: "radius-system" -metricsProvider: - prometheus: - enabled: true - path: "/metrics" - port: 9090 -server: - host: "0.0.0.0" - port: 5443 -workerServer: - maxOperationConcurrency: 10 - maxOperationRetryCount: 2 -ucp: - kind: kubernetes -``` - -### UCP -```yaml -location: 'global' -databaseProvider: - provider: "apiserver" - apiserver: - context: "" - namespace: "radius-system" -secretProvider: - provider: "kubernetes" -planes: - - id: "/planes/radius/local" - properties: - resourceProviders: - Applications.Core: "http://applications-rp.radius-system:5443" - Applications.Dapr: "http://applications-rp.radius-system:5443" - Applications.Datastores: "http://applications-rp.radius-system:5443" - Applications.Messaging: "http://applications-rp.radius-system:5443" - Microsoft.Resources: "http://bicep-de.radius-system:6443" - kind: "UCPNative" - - id: "/planes/aws/aws" - properties: - kind: "AWS" -metricsProvider: - prometheus: - enabled: true - path: "/metrics" - port: 9090 -``` +See the configuration files in `cmd//*.yaml` for examples of configuration files. ## Environment Variables diff --git a/pkg/armrpc/asyncoperation/statusmanager/statusmanager.go b/pkg/armrpc/asyncoperation/statusmanager/statusmanager.go index 091b80e1a2..bf0e0a2a7b 100644 --- a/pkg/armrpc/asyncoperation/statusmanager/statusmanager.go +++ b/pkg/armrpc/asyncoperation/statusmanager/statusmanager.go @@ -26,9 +26,9 @@ import ( v1 "github.com/radius-project/radius/pkg/armrpc/api/v1" ctrl "github.com/radius-project/radius/pkg/armrpc/asyncoperation/controller" "github.com/radius-project/radius/pkg/components/database" + "github.com/radius-project/radius/pkg/components/metrics" "github.com/radius-project/radius/pkg/components/queue" - "github.com/radius-project/radius/pkg/metrics" - "github.com/radius-project/radius/pkg/trace" + "github.com/radius-project/radius/pkg/components/trace" "github.com/radius-project/radius/pkg/ucp/resources" "github.com/google/uuid" diff --git a/pkg/armrpc/asyncoperation/worker/worker.go b/pkg/armrpc/asyncoperation/worker/worker.go index 587068a3bc..662f323014 100644 --- a/pkg/armrpc/asyncoperation/worker/worker.go +++ b/pkg/armrpc/asyncoperation/worker/worker.go @@ -29,10 +29,10 @@ import ( ctrl "github.com/radius-project/radius/pkg/armrpc/asyncoperation/controller" manager "github.com/radius-project/radius/pkg/armrpc/asyncoperation/statusmanager" "github.com/radius-project/radius/pkg/components/database" + "github.com/radius-project/radius/pkg/components/metrics" "github.com/radius-project/radius/pkg/components/queue" + "github.com/radius-project/radius/pkg/components/trace" "github.com/radius-project/radius/pkg/logging" - "github.com/radius-project/radius/pkg/metrics" - "github.com/radius-project/radius/pkg/trace" "github.com/radius-project/radius/pkg/ucp/resources" "github.com/radius-project/radius/pkg/ucp/ucplog" diff --git a/pkg/armrpc/hostoptions/env.go b/pkg/armrpc/hostoptions/env.go index 8770254dd5..9da432fd54 100644 --- a/pkg/armrpc/hostoptions/env.go +++ b/pkg/armrpc/hostoptions/env.go @@ -22,25 +22,20 @@ import ( ) const ( - RadiusDevEnvironment = "dev" - RadiusSelfHostedDevEnvironment = "self-hosted-dev" - RadiusSelfHostedEnvironment = "self-hosted" - RadiusDogfood = "df-westus3" - RadiusCanaryEastUS2EUAP = "prod-eastus2euap" - RadiusCanaryCentralUS2EUAP = "prod-centralus2euap" - RadiusProdPrefix = "prod" + RadiusDevEnvironment = "dev" + RadiusSelfHostedEnvironment = "self-hosted" ) var currentEnv = RadiusDevEnvironment -// Environment returns the current environment name. +// Environment returns the current environment name. Can be configured by the RADIUS_ENV environment variables. Defaults to "dev" if not set. func Environment() string { return currentEnv } // IsDevelopment returns true if the current environment is development environment. func IsDevelopment() bool { - return strings.HasPrefix(Environment(), RadiusDevEnvironment) || strings.HasPrefix(Environment(), RadiusSelfHostedDevEnvironment) + return strings.HasPrefix(Environment(), RadiusDevEnvironment) } // IsSelfHosted returns true if the current environment is self-hosted environment. @@ -48,22 +43,6 @@ func IsSelfHosted() bool { return strings.HasPrefix(Environment(), RadiusSelfHostedEnvironment) } -// IsDogfood returns true if the current environment is dogfood environment. -func IsDogfood() bool { - return Environment() == RadiusDogfood -} - -// IsCanary returns true if the current environment is canary region. -func IsCanary() bool { - env := Environment() - return env == RadiusCanaryEastUS2EUAP || env == RadiusCanaryCentralUS2EUAP -} - -// IsProduction returns true if the current environment is production, but not canary. -func IsProduction() bool { - return !IsCanary() && strings.HasPrefix(Environment(), RadiusProdPrefix) -} - func init() { currentEnv = strings.TrimSpace(strings.ToLower(os.Getenv("RADIUS_ENV"))) if currentEnv == "" { diff --git a/pkg/armrpc/hostoptions/providerconfig.go b/pkg/armrpc/hostoptions/providerconfig.go index e8f19f1fb0..1708cf0f5e 100644 --- a/pkg/armrpc/hostoptions/providerconfig.go +++ b/pkg/armrpc/hostoptions/providerconfig.go @@ -20,32 +20,32 @@ import ( "fmt" "github.com/radius-project/radius/pkg/components/database/databaseprovider" + "github.com/radius-project/radius/pkg/components/metrics/metricsservice" + "github.com/radius-project/radius/pkg/components/profiler/profilerservice" "github.com/radius-project/radius/pkg/components/queue/queueprovider" "github.com/radius-project/radius/pkg/components/secret/secretprovider" + "github.com/radius-project/radius/pkg/components/trace/traceservice" - metricsprovider "github.com/radius-project/radius/pkg/metrics/provider" - profilerprovider "github.com/radius-project/radius/pkg/profiler/provider" - "github.com/radius-project/radius/pkg/trace" "github.com/radius-project/radius/pkg/ucp/config" "github.com/radius-project/radius/pkg/ucp/ucplog" ) // ProviderConfig includes the resource provider configuration. type ProviderConfig struct { - Env EnvironmentOptions `yaml:"environment"` - Identity IdentityOptions `yaml:"identity"` - DatabaseProvider databaseprovider.Options `yaml:"databaseProvider"` - SecretProvider secretprovider.SecretProviderOptions `yaml:"secretProvider"` - QueueProvider queueprovider.QueueProviderOptions `yaml:"queueProvider"` - Server *ServerOptions `yaml:"server,omitempty"` - WorkerServer *WorkerServerOptions `yaml:"workerServer,omitempty"` - MetricsProvider metricsprovider.MetricsProviderOptions `yaml:"metricsProvider"` - TracerProvider trace.Options `yaml:"tracerProvider"` - ProfilerProvider profilerprovider.ProfilerProviderOptions `yaml:"profilerProvider"` - UCP config.UCPOptions `yaml:"ucp"` - Logging ucplog.LoggingOptions `yaml:"logging"` - Bicep BicepOptions `yaml:"bicep,omitempty"` - Terraform TerraformOptions `yaml:"terraform,omitempty"` + Env EnvironmentOptions `yaml:"environment"` + Identity IdentityOptions `yaml:"identity"` + DatabaseProvider databaseprovider.Options `yaml:"databaseProvider"` + SecretProvider secretprovider.SecretProviderOptions `yaml:"secretProvider"` + QueueProvider queueprovider.QueueProviderOptions `yaml:"queueProvider"` + Server *ServerOptions `yaml:"server,omitempty"` + WorkerServer *WorkerServerOptions `yaml:"workerServer,omitempty"` + MetricsProvider metricsservice.Options `yaml:"metricsProvider"` + TracerProvider traceservice.Options `yaml:"tracerProvider"` + ProfilerProvider profilerservice.Options `yaml:"profilerProvider"` + UCP config.UCPOptions `yaml:"ucp"` + Logging ucplog.LoggingOptions `yaml:"logging"` + Bicep BicepOptions `yaml:"bicep,omitempty"` + Terraform TerraformOptions `yaml:"terraform,omitempty"` // FeatureFlags includes the list of feature flags. FeatureFlags []string `yaml:"featureFlags"` diff --git a/pkg/ucp/hosting/hosting.go b/pkg/components/hosting/hosting.go similarity index 100% rename from pkg/ucp/hosting/hosting.go rename to pkg/components/hosting/hosting.go diff --git a/pkg/ucp/hosting/hosting_test.go b/pkg/components/hosting/hosting_test.go similarity index 100% rename from pkg/ucp/hosting/hosting_test.go rename to pkg/components/hosting/hosting_test.go diff --git a/pkg/ucp/hosting/run.go b/pkg/components/hosting/run.go similarity index 100% rename from pkg/ucp/hosting/run.go rename to pkg/components/hosting/run.go diff --git a/pkg/metrics/README.md b/pkg/components/metrics/README.md similarity index 100% rename from pkg/metrics/README.md rename to pkg/components/metrics/README.md diff --git a/pkg/metrics/asyncoperationmetrics.go b/pkg/components/metrics/asyncoperationmetrics.go similarity index 100% rename from pkg/metrics/asyncoperationmetrics.go rename to pkg/components/metrics/asyncoperationmetrics.go diff --git a/pkg/metrics/metrics.go b/pkg/components/metrics/metrics.go similarity index 100% rename from pkg/metrics/metrics.go rename to pkg/components/metrics/metrics.go diff --git a/pkg/metrics/provider/options.go b/pkg/components/metrics/metricsservice/options.go similarity index 52% rename from pkg/metrics/provider/options.go rename to pkg/components/metrics/metricsservice/options.go index c61f24744c..71acfb7b7f 100644 --- a/pkg/metrics/provider/options.go +++ b/pkg/components/metrics/metricsservice/options.go @@ -14,17 +14,25 @@ See the License for the specific language governing permissions and limitations under the License. */ -package provider +package metricsservice -// MetricsProviderOptions represents the options of the providers for publishing metrics. -type MetricsProviderOptions struct { - ServiceName string `yaml:"serviceName,omitempty"` - Prometheus PrometheusOptions `yaml:"prometheus,omitempty"` +// Options represents the options of the providers for publishing metrics. +type Options struct { + // Enabled is the flag to enable the metrics service. + Enabled bool `yaml:"enabled"` + + // ServiceName is the name of the service. + ServiceName string `yaml:"serviceName,omitempty"` + + // Prometheus is the options for the prometheus metrics provider. + Prometheus *PrometheusOptions `yaml:"prometheus,omitempty"` } // PrometheusOptions represents prometheus metrics provider options. type PrometheusOptions struct { - Enabled bool `yaml:"enabled"` - Path string `yaml:"path"` - Port int `yaml:"port"` + // Path is the path where the prometheus metrics are exposed. + Path string `yaml:"path"` + + // Address is the address where the prometheus metrics are exposed. + Port int `yaml:"port"` } diff --git a/pkg/metrics/provider/prometheusexporter.go b/pkg/components/metrics/metricsservice/prometheusexporter.go similarity index 94% rename from pkg/metrics/provider/prometheusexporter.go rename to pkg/components/metrics/metricsservice/prometheusexporter.go index b7e4893cb8..eba3e45aca 100644 --- a/pkg/metrics/provider/prometheusexporter.go +++ b/pkg/components/metrics/metricsservice/prometheusexporter.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package provider +package metricsservice import ( "net/http" @@ -38,7 +38,7 @@ type PrometheusExporter struct { // NewPrometheusExporter creates a PrometheusExporter instance with a MeterProvider and a Handler, // and returns it along with any errors. -func NewPrometheusExporter(options *MetricsProviderOptions) (*PrometheusExporter, error) { +func NewPrometheusExporter(options *Options) (*PrometheusExporter, error) { exporter, err := prometheus.New() if err != nil { return nil, err diff --git a/pkg/metrics/service/service.go b/pkg/components/metrics/metricsservice/service.go similarity index 81% rename from pkg/metrics/service/service.go rename to pkg/components/metrics/metricsservice/service.go index 915205f22c..ad517f28a4 100644 --- a/pkg/metrics/service/service.go +++ b/pkg/components/metrics/metricsservice/service.go @@ -24,21 +24,14 @@ import ( "strconv" "time" - "github.com/radius-project/radius/pkg/metrics" - "github.com/radius-project/radius/pkg/metrics/provider" + "github.com/radius-project/radius/pkg/components/metrics" "github.com/radius-project/radius/pkg/ucp/ucplog" "go.opentelemetry.io/contrib/instrumentation/runtime" ) +// Service implements the metrics service. type Service struct { - Options HostOptions -} - -// NewService creates a new Service instance with the given HostOptions. -func NewService(options HostOptions) *Service { - return &Service{ - Options: options, - } + Options *Options } // Name returns the name of the metrics service. @@ -52,7 +45,7 @@ func (s *Service) Name() string { func (s *Service) Run(ctx context.Context) error { logger := ucplog.FromContextOrDiscard(ctx) - pme, err := provider.NewPrometheusExporter(s.Options.Config) + pme, err := NewPrometheusExporter(s.Options) if err != nil { return err } @@ -68,8 +61,8 @@ func (s *Service) Run(ctx context.Context) error { } mux := http.NewServeMux() - mux.HandleFunc(s.Options.Config.Prometheus.Path, pme.Handler.ServeHTTP) - metricsPort := strconv.Itoa(s.Options.Config.Prometheus.Port) + mux.HandleFunc(s.Options.Prometheus.Path, pme.Handler.ServeHTTP) + metricsPort := strconv.Itoa(s.Options.Prometheus.Port) server := &http.Server{ Addr: ":" + metricsPort, Handler: mux, diff --git a/pkg/metrics/recipeenginemetrics.go b/pkg/components/metrics/recipeenginemetrics.go similarity index 100% rename from pkg/metrics/recipeenginemetrics.go rename to pkg/components/metrics/recipeenginemetrics.go diff --git a/pkg/metrics/types.go b/pkg/components/metrics/types.go similarity index 100% rename from pkg/metrics/types.go rename to pkg/components/metrics/types.go diff --git a/pkg/profiler/service/service.go b/pkg/components/profiler/profilerservice/service.go similarity index 82% rename from pkg/profiler/service/service.go rename to pkg/components/profiler/profilerservice/service.go index 96a7668d70..4bd70352d6 100644 --- a/pkg/profiler/service/service.go +++ b/pkg/components/profiler/profilerservice/service.go @@ -26,15 +26,18 @@ import ( "github.com/radius-project/radius/pkg/ucp/ucplog" ) -type Service struct { - Options HostOptions +// Options represents the options for enabling pprof profiler. +type Options struct { + // Enabled is a flag to enable the profiler. + Enabled bool `yaml:"enabled,omitempty"` + + // Port is the port on which the profiler server listens. + Port int `yaml:"port,omitempty"` } -// NewService of profiler package returns a new Service with the configs needed -func NewService(options HostOptions) *Service { - return &Service{ - Options: options, - } +// Service is the profiler service. +type Service struct { + Options *Options } // Name returns the name of the profiler service. @@ -47,7 +50,7 @@ func (s *Service) Name() string { func (s *Service) Run(ctx context.Context) error { logger := ucplog.FromContextOrDiscard(ctx) - profilerPort := strconv.Itoa(s.Options.Config.Port) + profilerPort := strconv.Itoa(s.Options.Port) server := &http.Server{ Addr: ":" + profilerPort, BaseContext: func(ln net.Listener) context.Context { diff --git a/pkg/components/testhost/host.go b/pkg/components/testhost/host.go index 83f5f19cc9..0a01f98cc7 100644 --- a/pkg/components/testhost/host.go +++ b/pkg/components/testhost/host.go @@ -31,7 +31,7 @@ import ( "testing" "time" - "github.com/radius-project/radius/pkg/ucp/hosting" + "github.com/radius-project/radius/pkg/components/hosting" "github.com/radius-project/radius/test/testcontext" "github.com/stretchr/testify/require" ) diff --git a/pkg/trace/doc.go b/pkg/components/trace/doc.go similarity index 100% rename from pkg/trace/doc.go rename to pkg/components/trace/doc.go diff --git a/pkg/trace/options.go b/pkg/components/trace/traceservice/options.go similarity index 90% rename from pkg/trace/options.go rename to pkg/components/trace/traceservice/options.go index bf41bc760a..a063c477b7 100644 --- a/pkg/trace/options.go +++ b/pkg/components/trace/traceservice/options.go @@ -14,10 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -package trace +package traceservice // Options represents the trace options. type Options struct { + // Enabled configures whether tracing is enabled. + Enabled bool `yaml:"enabled"` // ServiceName represents the name of service. ServiceName string `yaml:"serviceName,omitempty"` // Zipkin represents zipkin options. diff --git a/pkg/trace/trace.go b/pkg/components/trace/traceservice/service.go similarity index 81% rename from pkg/trace/trace.go rename to pkg/components/trace/traceservice/service.go index 72bedc3438..84492973da 100644 --- a/pkg/trace/trace.go +++ b/pkg/components/trace/traceservice/service.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -13,7 +13,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package trace + +package traceservice import ( "context" @@ -28,7 +29,7 @@ import ( // Service implements the hosting.Service interface for the tracer. type Service struct { - Options Options + Options *Options } // Name gets the service name. @@ -38,7 +39,7 @@ func (s *Service) Name() string { // Run runs the tracer service. func (s *Service) Run(ctx context.Context) error { - shutdown, err := InitTracer(s.Options) + shutdown, err := initTracer(s.Options) if err != nil { return err } @@ -47,9 +48,8 @@ func (s *Service) Run(ctx context.Context) error { return shutdown(ctx) } -// InitTracer sets up a tracer provider with a sampler and resource attributes, and optionally registers a Zipkin exporter -// and batcher. It returns a shutdown function and an error if one occurs. -func InitTracer(opts Options) (func(context.Context) error, error) { +// initTracer configures a tracer provider with the given options. +func initTracer(opts *Options) (func(context.Context) error, error) { tp := sdktrace.NewTracerProvider( sdktrace.WithSampler(sdktrace.AlwaysSample()), sdktrace.WithResource(resource.NewWithAttributes( @@ -62,10 +62,12 @@ func InitTracer(opts Options) (func(context.Context) error, error) { if err != nil { return nil, err } + batcher := sdktrace.NewBatchSpanProcessor(exporter) tp.RegisterSpanProcessor(batcher) } + otel.SetTracerProvider(tp) otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{})) return tp.Shutdown, nil diff --git a/pkg/trace/util.go b/pkg/components/trace/util.go similarity index 100% rename from pkg/trace/util.go rename to pkg/components/trace/util.go diff --git a/pkg/trace/util_test.go b/pkg/components/trace/util_test.go similarity index 100% rename from pkg/trace/util_test.go rename to pkg/components/trace/util_test.go diff --git a/pkg/controller/service.go b/pkg/controller/service.go index 1c55ede895..422aee16d5 100644 --- a/pkg/controller/service.go +++ b/pkg/controller/service.go @@ -21,9 +21,9 @@ import ( "fmt" "github.com/radius-project/radius/pkg/armrpc/hostoptions" + "github.com/radius-project/radius/pkg/components/hosting" radappiov1alpha3 "github.com/radius-project/radius/pkg/controller/api/radapp.io/v1alpha3" "github.com/radius-project/radius/pkg/controller/reconciler" - "github.com/radius-project/radius/pkg/ucp/hosting" "github.com/radius-project/radius/pkg/ucp/ucplog" "k8s.io/apimachinery/pkg/runtime" @@ -64,8 +64,8 @@ func (*Service) Name() string { func (s *Service) Run(ctx context.Context) error { logger := ucplog.FromContextOrDiscard(ctx) - metricsAddr := "0" // Disable metrics - if s.Options.Config.MetricsProvider.Prometheus.Enabled { + metricsAddr := "0" // Setting the address to 0 will disable the metrics server. + if s.Options.Config.MetricsProvider.Enabled { metricsAddr = fmt.Sprintf(":%d", s.Options.Config.MetricsProvider.Prometheus.Port) } diff --git a/pkg/dynamicrp/config.go b/pkg/dynamicrp/config.go index 1ffa71bd47..8a658ae039 100644 --- a/pkg/dynamicrp/config.go +++ b/pkg/dynamicrp/config.go @@ -21,11 +21,11 @@ import ( "github.com/radius-project/radius/pkg/armrpc/hostoptions" "github.com/radius-project/radius/pkg/components/database/databaseprovider" + "github.com/radius-project/radius/pkg/components/metrics/metricsservice" + "github.com/radius-project/radius/pkg/components/profiler/profilerservice" "github.com/radius-project/radius/pkg/components/queue/queueprovider" "github.com/radius-project/radius/pkg/components/secret/secretprovider" - metricsprovider "github.com/radius-project/radius/pkg/metrics/provider" - profilerprovider "github.com/radius-project/radius/pkg/profiler/provider" - "github.com/radius-project/radius/pkg/trace" + "github.com/radius-project/radius/pkg/components/trace/traceservice" ucpconfig "github.com/radius-project/radius/pkg/ucp/config" "github.com/radius-project/radius/pkg/ucp/ucplog" "gopkg.in/yaml.v3" @@ -48,10 +48,10 @@ type Config struct { Logging ucplog.LoggingOptions `yaml:"logging"` // Metrics is the configuration for the metrics endpoint. - Metrics metricsprovider.MetricsProviderOptions `yaml:"metricsProvider"` + Metrics metricsservice.Options `yaml:"metricsProvider"` // Profiler is the configuration for the profiler endpoint. - Profiler profilerprovider.ProfilerProviderOptions `yaml:"profilerProvider"` + Profiler profilerservice.Options `yaml:"profilerProvider"` // Queue is the configuration for the message queue. Queue queueprovider.QueueProviderOptions `yaml:"queueProvider"` @@ -66,7 +66,7 @@ type Config struct { Terraform hostoptions.TerraformOptions `yaml:"terraform"` // Tracing is the configuration for the tracing system. - Tracing trace.Options `yaml:"tracerProvider"` + Tracing traceservice.Options `yaml:"tracerProvider"` // UCPConfig is the configuration for the connection to UCP. UCP ucpconfig.UCPOptions `yaml:"ucp"` diff --git a/pkg/dynamicrp/server/server.go b/pkg/dynamicrp/server/server.go index d6e2cc24c1..ad190b0d89 100644 --- a/pkg/dynamicrp/server/server.go +++ b/pkg/dynamicrp/server/server.go @@ -17,13 +17,13 @@ limitations under the License. package server import ( + "github.com/radius-project/radius/pkg/components/hosting" + "github.com/radius-project/radius/pkg/components/metrics/metricsservice" + "github.com/radius-project/radius/pkg/components/profiler/profilerservice" + "github.com/radius-project/radius/pkg/components/trace/traceservice" "github.com/radius-project/radius/pkg/dynamicrp" "github.com/radius-project/radius/pkg/dynamicrp/backend" "github.com/radius-project/radius/pkg/dynamicrp/frontend" - metricsservice "github.com/radius-project/radius/pkg/metrics/service" - profilerservice "github.com/radius-project/radius/pkg/profiler/service" - "github.com/radius-project/radius/pkg/trace" - "github.com/radius-project/radius/pkg/ucp/hosting" ) // NewServer initializes a host for UCP based on the provided options. @@ -31,22 +31,18 @@ func NewServer(options *dynamicrp.Options) (*hosting.Host, error) { services := []hosting.Service{} // Metrics is provided via a service. - if options.Config.Metrics.Prometheus.Enabled { - services = append(services, metricsservice.NewService(metricsservice.HostOptions{ - Config: &options.Config.Metrics, - })) + if options.Config.Metrics.Enabled { + services = append(services, &metricsservice.Service{Options: &options.Config.Metrics}) } // Profiling is provided via a service. if options.Config.Profiler.Enabled { - services = append(services, profilerservice.NewService(profilerservice.HostOptions{ - Config: &options.Config.Profiler, - })) + services = append(services, &profilerservice.Service{Options: &options.Config.Profiler}) } // Tracing is provided via a service. - if options.Config.Tracing.ServiceName != "" { - services = append(services, &trace.Service{Options: options.Config.Tracing}) + if options.Config.Tracing.Enabled { + services = append(services, &traceservice.Service{Options: &options.Config.Tracing}) } services = append(services, frontend.NewService(options)) diff --git a/pkg/metrics/service/hostoptions.go b/pkg/metrics/service/hostoptions.go deleted file mode 100644 index 009d3bea90..0000000000 --- a/pkg/metrics/service/hostoptions.go +++ /dev/null @@ -1,35 +0,0 @@ -/* -Copyright 2023 The Radius Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package metricsservice - -import ( - "github.com/radius-project/radius/pkg/armrpc/hostoptions" - "github.com/radius-project/radius/pkg/metrics/provider" -) - -// HostOptions defines all of the settings that our metric's execution environment provides. -type HostOptions struct { - // Config is the bootstrap metrics configuration loaded from config file. - Config *provider.MetricsProviderOptions -} - -// NewHostOptionsFromEnvironment creates a new HostOptions object from a ProviderConfig object. -func NewHostOptionsFromEnvironment(options hostoptions.ProviderConfig) HostOptions { - return HostOptions{ - Config: &options.MetricsProvider, - } -} diff --git a/pkg/portableresources/processors/resourceclient.go b/pkg/portableresources/processors/resourceclient.go index f2e95261ad..f53140d5a0 100644 --- a/pkg/portableresources/processors/resourceclient.go +++ b/pkg/portableresources/processors/resourceclient.go @@ -28,8 +28,8 @@ import ( aztoken "github.com/radius-project/radius/pkg/azure/tokencredentials" "github.com/radius-project/radius/pkg/cli/clients" "github.com/radius-project/radius/pkg/cli/clients_new/generated" + "github.com/radius-project/radius/pkg/components/trace" "github.com/radius-project/radius/pkg/sdk" - "github.com/radius-project/radius/pkg/trace" "github.com/radius-project/radius/pkg/ucp/resources" resources_azure "github.com/radius-project/radius/pkg/ucp/resources/azure" resources_kubernetes "github.com/radius-project/radius/pkg/ucp/resources/kubernetes" diff --git a/pkg/profiler/provider/options.go b/pkg/profiler/provider/options.go deleted file mode 100644 index 4a2005a6f4..0000000000 --- a/pkg/profiler/provider/options.go +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2023 The Radius Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package provider - -// ProfilerProviderOptions represents the options for enabling pprof profiler. -type ProfilerProviderOptions struct { - Enabled bool `yaml:"enabled,omitempty"` - Port int `yaml:"port,omitempty"` -} diff --git a/pkg/profiler/service/hostoptions.go b/pkg/profiler/service/hostoptions.go deleted file mode 100644 index 795ac7d334..0000000000 --- a/pkg/profiler/service/hostoptions.go +++ /dev/null @@ -1,34 +0,0 @@ -/* -Copyright 2023 The Radius Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package profilerservice - -import ( - "github.com/radius-project/radius/pkg/armrpc/hostoptions" - "github.com/radius-project/radius/pkg/profiler/provider" -) - -type HostOptions struct { - // Config is the bootstrap profiler configuration loaded from config file. - Config *provider.ProfilerProviderOptions -} - -// NewHostOptionsFromEnvironment of profiler/hostoptions package returns the HostOptions for profiler service. -func NewHostOptionsFromEnvironment(options hostoptions.ProviderConfig) HostOptions { - return HostOptions{ - Config: &options.ProfilerProvider, - } -} diff --git a/pkg/recipes/driver/bicep.go b/pkg/recipes/driver/bicep.go index 8e1e9dba4e..745d8b4d1c 100644 --- a/pkg/recipes/driver/bicep.go +++ b/pkg/recipes/driver/bicep.go @@ -30,8 +30,8 @@ import ( "golang.org/x/sync/errgroup" "oras.land/oras-go/v2/registry/remote" + "github.com/radius-project/radius/pkg/components/metrics" coredm "github.com/radius-project/radius/pkg/corerp/datamodel" - "github.com/radius-project/radius/pkg/metrics" "github.com/radius-project/radius/pkg/portableresources/datamodel" "github.com/radius-project/radius/pkg/portableresources/processors" "github.com/radius-project/radius/pkg/recipes" diff --git a/pkg/recipes/engine/engine.go b/pkg/recipes/engine/engine.go index 0a878b8af9..e981ed54e8 100644 --- a/pkg/recipes/engine/engine.go +++ b/pkg/recipes/engine/engine.go @@ -21,7 +21,7 @@ import ( "fmt" "time" - "github.com/radius-project/radius/pkg/metrics" + "github.com/radius-project/radius/pkg/components/metrics" "github.com/radius-project/radius/pkg/recipes" "github.com/radius-project/radius/pkg/recipes/configloader" recipedriver "github.com/radius-project/radius/pkg/recipes/driver" diff --git a/pkg/recipes/terraform/execute.go b/pkg/recipes/terraform/execute.go index 464e9b512d..623cd827af 100644 --- a/pkg/recipes/terraform/execute.go +++ b/pkg/recipes/terraform/execute.go @@ -27,8 +27,8 @@ import ( install "github.com/hashicorp/hc-install" "github.com/hashicorp/terraform-exec/tfexec" tfjson "github.com/hashicorp/terraform-json" + "github.com/radius-project/radius/pkg/components/metrics" "github.com/radius-project/radius/pkg/components/secret/secretprovider" - "github.com/radius-project/radius/pkg/metrics" "github.com/radius-project/radius/pkg/recipes/recipecontext" "github.com/radius-project/radius/pkg/recipes/terraform/config" "github.com/radius-project/radius/pkg/recipes/terraform/config/backends" diff --git a/pkg/recipes/terraform/install.go b/pkg/recipes/terraform/install.go index d318e3d90f..ffe8e9cbda 100644 --- a/pkg/recipes/terraform/install.go +++ b/pkg/recipes/terraform/install.go @@ -28,7 +28,7 @@ import ( "github.com/hashicorp/hc-install/releases" "github.com/hashicorp/hc-install/src" "github.com/hashicorp/terraform-exec/tfexec" - "github.com/radius-project/radius/pkg/metrics" + "github.com/radius-project/radius/pkg/components/metrics" "github.com/radius-project/radius/pkg/ucp/ucplog" "go.opentelemetry.io/otel/attribute" ) diff --git a/pkg/recipes/terraform/module.go b/pkg/recipes/terraform/module.go index 0df9b950f8..f25ff731d3 100644 --- a/pkg/recipes/terraform/module.go +++ b/pkg/recipes/terraform/module.go @@ -26,7 +26,7 @@ import ( getter "github.com/hashicorp/go-getter" "github.com/hashicorp/terraform-config-inspect/tfconfig" "github.com/hashicorp/terraform-exec/tfexec" - "github.com/radius-project/radius/pkg/metrics" + "github.com/radius-project/radius/pkg/components/metrics" "github.com/radius-project/radius/pkg/recipes" "github.com/radius-project/radius/pkg/recipes/recipecontext" "github.com/radius-project/radius/pkg/recipes/terraform/config" diff --git a/pkg/ucp/config.go b/pkg/ucp/config.go index 7ef4a8ff56..b4f248a6b6 100644 --- a/pkg/ucp/config.go +++ b/pkg/ucp/config.go @@ -21,11 +21,11 @@ import ( "github.com/radius-project/radius/pkg/armrpc/hostoptions" "github.com/radius-project/radius/pkg/components/database/databaseprovider" + "github.com/radius-project/radius/pkg/components/metrics/metricsservice" + "github.com/radius-project/radius/pkg/components/profiler/profilerservice" "github.com/radius-project/radius/pkg/components/queue/queueprovider" "github.com/radius-project/radius/pkg/components/secret/secretprovider" - metricsprovider "github.com/radius-project/radius/pkg/metrics/provider" - profilerprovider "github.com/radius-project/radius/pkg/profiler/provider" - "github.com/radius-project/radius/pkg/trace" + "github.com/radius-project/radius/pkg/components/trace/traceservice" ucpconfig "github.com/radius-project/radius/pkg/ucp/config" "github.com/radius-project/radius/pkg/ucp/ucplog" "gopkg.in/yaml.v3" @@ -51,10 +51,10 @@ type Config struct { Logging ucplog.LoggingOptions `yaml:"logging"` // Metrics is the configuration for the metrics endpoint. - Metrics metricsprovider.MetricsProviderOptions `yaml:"metricsProvider"` + Metrics metricsservice.Options `yaml:"metricsProvider"` // Profiler is the configuration for the profiler endpoint. - Profiler profilerprovider.ProfilerProviderOptions `yaml:"profilerProvider"` + Profiler profilerservice.Options `yaml:"profilerProvider"` // Routing is the configuration for UCP routing. Routing RoutingConfig `yaml:"routing"` @@ -69,7 +69,7 @@ type Config struct { Server hostoptions.ServerOptions `yaml:"server"` // Tracing is the configuration for the tracing system. - Tracing trace.Options `yaml:"tracerProvider"` + Tracing traceservice.Options `yaml:"tracerProvider"` // UCPConfig is the configuration for the connection to UCP. UCP ucpconfig.UCPOptions `yaml:"ucp"` diff --git a/pkg/ucp/frontend/api/server.go b/pkg/ucp/frontend/api/server.go index 3dc47ad9b3..581f8c77e5 100644 --- a/pkg/ucp/frontend/api/server.go +++ b/pkg/ucp/frontend/api/server.go @@ -29,6 +29,7 @@ import ( armrpc_controller "github.com/radius-project/radius/pkg/armrpc/frontend/controller" "github.com/radius-project/radius/pkg/armrpc/frontend/defaultoperation" "github.com/radius-project/radius/pkg/armrpc/servicecontext" + "github.com/radius-project/radius/pkg/components/hosting" "github.com/radius-project/radius/pkg/middleware" "github.com/radius-project/radius/pkg/ucp" "github.com/radius-project/radius/pkg/ucp/datamodel" @@ -38,7 +39,6 @@ import ( "github.com/radius-project/radius/pkg/ucp/frontend/modules" radius_frontend "github.com/radius-project/radius/pkg/ucp/frontend/radius" "github.com/radius-project/radius/pkg/ucp/frontend/versions" - "github.com/radius-project/radius/pkg/ucp/hosting" "github.com/radius-project/radius/pkg/ucp/resources" "github.com/radius-project/radius/pkg/ucp/ucplog" diff --git a/pkg/ucp/server/server.go b/pkg/ucp/server/server.go index b7d3edc03f..04871a8389 100644 --- a/pkg/ucp/server/server.go +++ b/pkg/ucp/server/server.go @@ -17,39 +17,35 @@ limitations under the License. package server import ( - metricsservice "github.com/radius-project/radius/pkg/metrics/service" - profilerservice "github.com/radius-project/radius/pkg/profiler/service" - "github.com/radius-project/radius/pkg/trace" + "github.com/radius-project/radius/pkg/components/hosting" + "github.com/radius-project/radius/pkg/components/metrics/metricsservice" + "github.com/radius-project/radius/pkg/components/profiler/profilerservice" + "github.com/radius-project/radius/pkg/components/trace/traceservice" "github.com/radius-project/radius/pkg/ucp" "github.com/radius-project/radius/pkg/ucp/backend" "github.com/radius-project/radius/pkg/ucp/frontend/api" - "github.com/radius-project/radius/pkg/ucp/hosting" ) // NewServer initializes a host for UCP based on the provided options. func NewServer(options *ucp.Options) (*hosting.Host, error) { - hostingServices := []hosting.Service{ + services := []hosting.Service{ api.NewService(options), backend.NewService(options), } - if options.Config.Metrics.Prometheus.Enabled { - metricOptions := metricsservice.HostOptions{ - Config: &options.Config.Metrics, - } - hostingServices = append(hostingServices, metricsservice.NewService(metricOptions)) + if options.Config.Metrics.Enabled { + services = append(services, &metricsservice.Service{Options: &options.Config.Metrics}) } if options.Config.Profiler.Enabled { - profilerOptions := profilerservice.HostOptions{ - Config: &options.Config.Profiler, - } - hostingServices = append(hostingServices, profilerservice.NewService(profilerOptions)) + services = append(services, &profilerservice.Service{Options: &options.Config.Profiler}) } - hostingServices = append(hostingServices, &trace.Service{Options: options.Config.Tracing}) + if options.Config.Tracing.Enabled { + services = append(services, &traceservice.Service{Options: &options.Config.Tracing}) + } return &hosting.Host{ - Services: hostingServices, + Services: services, }, nil }