Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move shared services and host to components #8160

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
rynowak marked this conversation as resolved.
Show resolved Hide resolved
},
{
"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
rynowak marked this conversation as resolved.
Show resolved Hide resolved
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
rynowak marked this conversation as resolved.
Show resolved Hide resolved
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
rynowak marked this conversation as resolved.
Show resolved Hide resolved
}

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
Loading