Skip to content

Commit

Permalink
Move shared services and host to components
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rynowak committed Dec 20, 2024
1 parent defd40b commit f59e2e3
Show file tree
Hide file tree
Showing 53 changed files with 211 additions and 404 deletions.
18 changes: 0 additions & 18 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# - Disables metrics and profiler
#
environment:
name: self-hosted
name: "dev"
roleLocation: "global"
databaseProvider:
provider: "apiserver"
Expand All @@ -24,8 +24,9 @@ queueProvider:
secretProvider:
provider: "kubernetes"
metricsProvider:
enabled: false
serviceName: applications-rp
prometheus:
enabled: true
path: "/metrics"
port: 9092
profilerProvider:
Expand All @@ -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:
Expand Down
46 changes: 21 additions & 25 deletions cmd/applications-rp/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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()))
}

Expand Down
43 changes: 0 additions & 43 deletions cmd/applications-rp/radius-dev.yaml

This file was deleted.

14 changes: 9 additions & 5 deletions cmd/controller/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
},
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/dynamic-rp/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
10 changes: 8 additions & 2 deletions cmd/dynamic-rp/dynamicrp-dev.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is an example of configuration file.
environment:
name: Dev
name: "dev"
roleLocation: "global"
databaseProvider:
provider: "apiserver"
Expand All @@ -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
Expand Down
26 changes: 22 additions & 4 deletions cmd/rad/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions cmd/ucpd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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()))
}
6 changes: 4 additions & 2 deletions cmd/ucpd/ucp-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# - Disables metrics and profiler
#
environment:
name: Dev
name: "dev"
roleLocation: "global"
server:
port: 9000
Expand Down Expand Up @@ -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

Expand All @@ -81,6 +82,7 @@ logging:

# Tracing configuration
tracerProvider:
enabled: false
serviceName: "ucp"
zipkin:
url: "http://localhost:9411/api/v2/spans"
Loading

0 comments on commit f59e2e3

Please sign in to comment.