Skip to content

Commit 1616eb3

Browse files
committed
read jobname from flags
1 parent 3f1a186 commit 1616eb3

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

federated-learning-controller/internal/sidecar/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ go run main.go -metricfile <path-to-metric-file> -endpoint <otlp-grpc-endpoint>
1515
* `-metricfile` (required): The file path for the metrics that the sidecar should watch.
1616
* `-endpoint` (required): The OTLP/gRPC endpoint of the OpenTelemetry collector (e.g., `localhost:4317`).
1717
* `-interval` (optional): The interval in seconds for the reporter to automatically push metrics. The default is 60 seconds.
18+
* `-jobname` (optional): The name of the job. If not specified, the sidecar will use the default value `federated-learning-obs-sidecar`.
1819

1920
### Metric File Format
2021

federated-learning-controller/internal/sidecar/exporter/exporter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type Reporter struct {
2424
callbackRegistration metric.Registration
2525
}
2626

27-
func NewReporter(ctx context.Context, endpoint string, interval int) (*Reporter, error) {
27+
func NewReporter(ctx context.Context, endpoint string, interval int, jobName string) (*Reporter, error) {
2828
exporter, err := otlpmetricgrpc.New(
2929
ctx,
3030
otlpmetricgrpc.WithInsecure(),
@@ -41,7 +41,7 @@ func NewReporter(ctx context.Context, endpoint string, interval int) (*Reporter,
4141
resource.Default(),
4242
resource.NewWithAttributes(
4343
semconv.SchemaURL,
44-
semconv.ServiceNameKey.String("fl_sidecar"),
44+
semconv.ServiceNameKey.String(jobName),
4545
semconv.K8SNamespaceNameKey.String(namespace),
4646
semconv.K8SPodNameKey.String(podName),
4747
),

federated-learning-controller/internal/sidecar/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ var (
1717
metricFile string
1818
endpoint string
1919
reporterInterval int
20+
jobName string
2021
)
2122

2223
func main() {
2324
flag.StringVar(&metricFile, "metricfile", "", "Path to the metric file")
2425
flag.StringVar(&endpoint, "endpoint", "", "Target endpoint address")
2526
flag.IntVar(&reporterInterval, "interval", 60, "Reporter automatic push interval in seconds")
27+
flag.StringVar(&jobName, "jobname", "federated-learning-obs-sidecar", "Job name for the metric service")
2628
flag.Parse()
2729

2830
if metricFile == "" || endpoint == "" {
@@ -42,7 +44,7 @@ func main() {
4244
cancel()
4345
}()
4446

45-
reporter, err := exporter.NewReporter(ctx, endpoint, reporterInterval)
47+
reporter, err := exporter.NewReporter(ctx, endpoint, reporterInterval, jobName)
4648
if err != nil {
4749
log.Fatalf("Init metrics reporter failed: %v", err)
4850
}

0 commit comments

Comments
 (0)