Skip to content

Commit

Permalink
Fixes for use in local docker container (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
fraliv13 authored Feb 4, 2025
1 parent fa443ee commit 378b788
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cmd/rusid/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ func main() {
}
klog.InfoS("Components manager is running")

api := grpc_api.NewGrpcAPI(cfg.RusiGRPCPort)
api := grpc_api.NewGrpcAPI(cfg.RusiGRPCHost, cfg.RusiGRPCPort)
klog.InfoS("Rusi grpc server is running")
rt, err := runtime.NewRuntime(mainCtx, cfg, api, configLoader, compManager)
if err != nil {
klog.Error(err)
return
}

klog.InfoS("Rusid is started", "port", cfg.RusiGRPCPort,
klog.InfoS("Rusid is started", "host", cfg.RusiGRPCHost, "port", cfg.RusiGRPCPort,
"app id", cfg.AppID, "mode", cfg.Mode, "version", version.Version(),
"git commit", version.Commit(), "git version", version.GitVersion())
klog.InfoS("Rusid is using", "config", cfg)
Expand Down
3 changes: 3 additions & 0 deletions internal/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
configuration "rusi/pkg/custom-resource/configuration"
"strings"
"time"

jaeger_propagator "go.opentelemetry.io/contrib/propagators/jaeger"
Expand Down Expand Up @@ -55,6 +56,8 @@ func flushTracer(tp *tracesdk.TracerProvider) func() {

func getTracerProvider(url string, serviceName string) (*tracesdk.TracerProvider, error) {
// Set up a trace exporter
url = strings.TrimPrefix(url, "http://")

traceExporter, err := otlptracegrpc.New(context.Background(),
otlptracegrpc.WithEndpoint(url),
otlptracegrpc.WithInsecure())
Expand Down
7 changes: 4 additions & 3 deletions pkg/api/runtime/grpc/grpc_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import (
"k8s.io/klog/v2"
)

func NewGrpcAPI(port int, serverOptions ...grpc.ServerOption) runtime.Api {
return &grpcApi{port: port, serverOptions: serverOptions}
func NewGrpcAPI(host string, port int, serverOptions ...grpc.ServerOption) runtime.Api {
return &grpcApi{host: host, port: port, serverOptions: serverOptions}
}

type grpcApi struct {
host string
port int
server *rusiServerImpl
serverOptions []grpc.ServerOption
Expand All @@ -49,7 +50,7 @@ func (srv *grpcApi) Serve(ctx context.Context) error {
grpcServer := grpc.NewServer(srv.serverOptions...)
v1.RegisterRusiServer(grpcServer, srv.server)

lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%v", srv.port))
lis, err := net.Listen("tcp", fmt.Sprintf("%v:%v", srv.host, srv.port))
if err != nil {
klog.Fatalf("failed to listen: %v", err)
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/runtime/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

const (
defaultGRPCHost = "localhost"
defaultGRPCPort = 50003
defaultDiagnosticsPort = 8080
defaultEnableMetrics = true
Expand All @@ -17,6 +18,7 @@ const (
type ConfigBuilder struct {
mode string
rusiGRPCPort int
rusiGRPCHost string
diagnosticsPort int
enableMetrics bool
componentsPath string
Expand All @@ -27,6 +29,7 @@ type ConfigBuilder struct {

type Config struct {
Mode modes.RusiMode
RusiGRPCHost string
RusiGRPCPort int
DiagnosticsPort int
EnableMetrics bool
Expand All @@ -46,6 +49,7 @@ func (c *ConfigBuilder) AttachCmdFlags(
intVar func(p *int, name string, value int, usage string)) {

stringVar(&c.mode, "mode", string(modes.StandaloneMode), "Runtime mode for Rusi (kubernetes / standalone - default:standalone )")
stringVar(&c.rusiGRPCHost, "rusi-grpc-host", defaultGRPCHost, "gRPC host for the Rusi API to listen on")
intVar(&c.rusiGRPCPort, "rusi-grpc-port", defaultGRPCPort, "gRPC port for the Rusi API to listen on")
stringVar(&c.componentsPath, "components-path", "", "Path for components directory. If empty, components will not be loaded. Self-hosted mode only")
stringVar(&c.config, "config", "", "Path to config file, or name of a configuration object")
Expand All @@ -63,6 +67,7 @@ func (c *ConfigBuilder) Build() (Config, error) {

variables := map[string]string{
utils.AppID: c.appID,
utils.RusiGRPCHost: c.rusiGRPCHost,
utils.RusiGRPCPort: strconv.Itoa(c.rusiGRPCPort),
}

Expand All @@ -72,6 +77,7 @@ func (c *ConfigBuilder) Build() (Config, error) {

return Config{
Mode: modes.RusiMode(c.mode),
RusiGRPCHost: c.rusiGRPCHost,
RusiGRPCPort: c.rusiGRPCPort,
ComponentsPath: c.componentsPath,
Config: c.config,
Expand Down
2 changes: 2 additions & 0 deletions pkg/utils/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package utils
const (
// RusiGRPCPort is the rusi api grpc port.
RusiGRPCPort string = "RUSI_GRPC_PORT"
// RusiGRPCHost is the rusi api grpc host.
RusiGRPCHost string = "RUSI_GRPC_HOST"
// RusiMetricsPort is the rusi metrics port.
RusiMetricsPort string = "RUSI_METRICS_PORT"
// RusiProfilePort is the rusi performance profiling port.
Expand Down

0 comments on commit 378b788

Please sign in to comment.