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

Wire up the components with main #59

Merged
merged 39 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ad0228c
Add wrapper collector component
srikanthccv Dec 21, 2022
3dc7cb7
fix shutdown
srikanthccv Dec 21, 2022
75b7edb
Add simple client implementation
srikanthccv Dec 21, 2022
8ef991b
Add interfaces/types with documentation
srikanthccv Dec 22, 2022
8b92e37
merge init
srikanthccv Dec 23, 2022
dd0b0a5
Merge branch 'wrapped-collector' into simple-client
srikanthccv Dec 23, 2022
a1802fd
Add config manager
srikanthccv Dec 23, 2022
f8a65da
Add server client implementation
srikanthccv Dec 24, 2022
8e38599
Add service implementation
srikanthccv Dec 24, 2022
10d0b83
Wire up the components with main
srikanthccv Dec 24, 2022
fcce474
more error handling
srikanthccv Dec 25, 2022
44c4380
Update service/service.go
srikanthccv Dec 26, 2022
7daf1b7
Merge branch 'main' into init
srikanthccv Dec 28, 2022
58bab0e
Merge branch 'init' into wrapped-collector
srikanthccv Dec 28, 2022
6fe1b3d
Add restart test
srikanthccv Dec 28, 2022
7fb5495
Merge branch 'wrapped-collector' into simple-client
srikanthccv Dec 28, 2022
f21ca80
Fix TODO item in simpleClient
srikanthccv Dec 28, 2022
db8daed
Merge branch 'simple-client' into config-manager
srikanthccv Dec 28, 2022
2b1d6dd
Add default ID when not provided
srikanthccv Dec 28, 2022
f9e91a6
Resolve conflicts
srikanthccv Dec 28, 2022
3e9b61c
Satisfy the interface
srikanthccv Dec 28, 2022
dc85816
Merge branch 'server-client' into service
srikanthccv Dec 28, 2022
d70a54d
Remove unnecessary fields
srikanthccv Dec 28, 2022
d35e2de
Merge branch 'service' into glue-up
srikanthccv Dec 28, 2022
cea18d7
Merge branch main into glue-up
srikanthccv Mar 6, 2023
165585e
Merge branch 'main' into glue-up
srikanthccv Mar 15, 2023
24c55bc
fix: handle asynchronous errors
srikanthccv Mar 20, 2023
27b85d1
Resolve conflicts
srikanthccv Aug 3, 2023
98e3eda
resolve conflicts
srikanthccv Aug 3, 2023
96c841c
more conflicts
srikanthccv Aug 3, 2023
eaa2a76
Add otelcol state
srikanthccv Aug 3, 2023
e6ba0f9
WIP: copy the initial config and wait for first server response
srikanthccv Aug 3, 2023
629a57b
Update tests
srikanthccv Aug 3, 2023
3daa0cc
Reload on initial config always
srikanthccv Aug 4, 2023
e347f52
Merge branch 'main' into glue-up
srikanthccv Aug 7, 2023
94a81f6
Address review comments
srikanthccv Aug 7, 2023
d1a5da2
Cleanup
srikanthccv Aug 7, 2023
aa78b88
Merge branch 'main' into glue-up
srikanthccv Sep 2, 2023
145e9c3
Merge branch 'main' into glue-up
srikanthccv Sep 26, 2023
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
91 changes: 72 additions & 19 deletions cmd/signozcollector/main.go
Original file line number Diff line number Diff line change
@@ -1,43 +1,96 @@
package main

import (
"context"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"time"

"github.com/SigNoz/signoz-otel-collector/components"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/service"
"github.com/SigNoz/signoz-otel-collector/service"
"github.com/SigNoz/signoz-otel-collector/signozcol"
flag "github.com/spf13/pflag"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

func main() {

factories, err := components.Components()
// Command line flags
f := flag.NewFlagSet("Collector CLI Options", flag.ExitOnError)

f.Usage = func() {
fmt.Println(f.FlagUsages())
os.Exit(0)
}

f.String("config", "", "File path for the collector configuration")
f.String("manager-config", "", "File path for the agent manager configuration")
err := f.Parse(os.Args[1:])
if err != nil {
log.Fatalf("failed to build default components: %v", err)
log.Fatalf("Failed to parse args %v", err)
}

info := component.BuildInfo{
Command: "signoz-otel-collector",
Description: "SigNoz OTEL Collector",
Version: "latest",
collectorConfig, _ := f.GetString("config")
managerConfig, _ := f.GetString("manager-config")

// logger, err := zap.NewProduction()
logger, err := initZapLog()
if err != nil {
log.Fatalf("failed to initialize zap logger: %v", err)
}

params := service.CollectorSettings{
Factories: factories,
BuildInfo: info,
ctx := context.Background()

coll := signozcol.New(
signozcol.WrappedCollectorSettings{
ConfigPaths: []string{collectorConfig},
// TODO: Build version from git tag
Version: "0.63.0",
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved
Desc: "SigNoz OpenTelemetry Collector",
LoggingOpts: []zap.Option{zap.WithCaller(true)},
},
)

svc, err := service.New(coll, logger, managerConfig, collectorConfig)
if err != nil {
log.Fatalf("failed to create collector service: %v", err)
}

if err := run(params); err != nil {
log.Fatal(err)
ctx, cancel := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
defer cancel()

if err := runInteractive(ctx, logger, svc); err != nil {
log.Fatalf("failed to run service: %v", err)
}
}

func runInteractive(params service.CollectorSettings) error {
cmd := service.NewCommand(params)
err := cmd.Execute()
if err != nil {
return fmt.Errorf("application run finished with error: %w", err)
func runInteractive(ctx context.Context, logger *zap.Logger, svc service.Service) error {
if err := svc.Start(ctx); err != nil {
return fmt.Errorf("failed to start collector service: %w", err)
}

select {
case <-ctx.Done():
}

stopTimeoutCtx, stopCancel := context.WithTimeout(context.Background(), 5*time.Second)
defer stopCancel()

if err := svc.Shutdown(stopTimeoutCtx); err != nil {
return fmt.Errorf("failed to stop service: %w", err)
}

return nil
}

func initZapLog() (*zap.Logger, error) {
config := zap.NewDevelopmentConfig()
config.EncoderConfig.EncodeLevel = zapcore.LowercaseLevelEncoder
config.EncoderConfig.TimeKey = "timestamp"
config.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
logger, err := config.Build()
return logger, err
}
9 changes: 0 additions & 9 deletions cmd/signozcollector/main_others.go

This file was deleted.

1 change: 1 addition & 0 deletions config/default-manager-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
server_endpoint: ws://127.0.0.1:4320/v1/opamp