@@ -19,14 +19,12 @@ package service
19
19
import (
20
20
"context"
21
21
"errors"
22
- "flag"
23
22
"fmt"
24
23
"os"
25
24
"os/signal"
26
25
"runtime"
27
26
"syscall"
28
27
29
- "github.com/spf13/cobra"
30
28
"go.opentelemetry.io/contrib/zpages"
31
29
"go.opentelemetry.io/otel"
32
30
"go.opentelemetry.io/otel/metric"
@@ -36,12 +34,10 @@ import (
36
34
37
35
"go.opentelemetry.io/collector/component"
38
36
"go.opentelemetry.io/collector/config/configcheck"
39
- "go.opentelemetry.io/collector/config/configtelemetry"
40
37
"go.opentelemetry.io/collector/config/configunmarshaler"
41
38
"go.opentelemetry.io/collector/config/experimental/configsource"
42
39
"go.opentelemetry.io/collector/consumer/consumererror"
43
40
"go.opentelemetry.io/collector/extension/ballastextension"
44
- "go.opentelemetry.io/collector/internal/collector/telemetry"
45
41
"go.opentelemetry.io/collector/service/internal"
46
42
"go.opentelemetry.io/collector/service/internal/telemetrylogs"
47
43
"go.opentelemetry.io/collector/service/parserprovider"
@@ -59,20 +55,19 @@ const (
59
55
60
56
// (Internal note) Collector Lifecycle:
61
57
// - New constructs a new Collector.
62
- // - Run starts the collector and calls (*Collector).execute .
63
- // - execute calls setupConfigurationComponents to handle configuration.
58
+ // - Run starts the collector.
59
+ // - Run calls setupConfigurationComponents to handle configuration.
64
60
// If configuration parser fails, collector's config can be reloaded.
65
61
// Collector can be shutdown if parser gets a shutdown error.
66
- // - execute runs runAndWaitForShutdownEvent and waits for a shutdown event.
62
+ // - Run runs runAndWaitForShutdownEvent and waits for a shutdown event.
67
63
// SIGINT and SIGTERM, errors, and (*Collector).Shutdown can trigger the shutdown events.
68
64
// - Upon shutdown, pipelines are notified, then pipelines and extensions are shut down.
69
- // - Users can call (*Collector).Shutdown anytime to shutdown the collector.
65
+ // - Users can call (*Collector).Shutdown anytime to shut down the collector.
70
66
71
67
// Collector represents a server providing the OpenTelemetry Collector service.
72
68
type Collector struct {
73
- set CollectorSettings
74
- rootCmd * cobra.Command
75
- logger * zap.Logger
69
+ set CollectorSettings
70
+ logger * zap.Logger
76
71
77
72
tracerProvider trace.TracerProvider
78
73
meterProvider metric.MeterProvider
@@ -107,57 +102,17 @@ func New(set CollectorSettings) (*Collector, error) {
107
102
set .ConfigUnmarshaler = configunmarshaler .NewDefault ()
108
103
}
109
104
110
- col := & Collector {
105
+ return & Collector {
111
106
set : set ,
112
107
stateChannel : make (chan State , Closed + 1 ),
113
- }
114
-
115
- rootCmd := & cobra.Command {
116
- Use : set .BuildInfo .Command ,
117
- Version : set .BuildInfo .Version ,
118
- RunE : func (cmd * cobra.Command , args []string ) error {
119
- return col .execute (cmd .Context ())
120
- },
121
- }
122
-
123
- // TODO: coalesce this code and expose this information to other components.
124
- flagSet := new (flag.FlagSet )
125
- addFlagsFns := []func (* flag.FlagSet ){
126
- configtelemetry .Flags ,
127
- parserprovider .Flags ,
128
- telemetry .Flags ,
129
- telemetrylogs .Flags ,
130
- }
131
- for _ , addFlags := range addFlagsFns {
132
- addFlags (flagSet )
133
- }
134
- rootCmd .Flags ().AddGoFlagSet (flagSet )
135
- col .rootCmd = rootCmd
136
-
137
- return col , nil
138
- }
139
-
140
- // Run starts the collector according to the command and configuration
141
- // given by the user, and waits for it to complete.
142
- // Consecutive calls to Run are not allowed, Run shouldn't be called
143
- // once a collector is shut down.
144
- func (col * Collector ) Run () error {
145
- // From this point on do not show usage in case of error.
146
- col .rootCmd .SilenceUsage = true
147
-
148
- return col .rootCmd .Execute ()
108
+ }, nil
149
109
}
150
110
151
111
// GetStateChannel returns state channel of the collector server.
152
112
func (col * Collector ) GetStateChannel () chan State {
153
113
return col .stateChannel
154
114
}
155
115
156
- // Command returns Collector's root command.
157
- func (col * Collector ) Command () * cobra.Command {
158
- return col .rootCmd
159
- }
160
-
161
116
// GetLogger returns logger used by the Collector.
162
117
// The logger is initialized after collector server start.
163
118
func (col * Collector ) GetLogger () * zap.Logger {
@@ -246,7 +201,9 @@ func (col *Collector) setupConfigurationComponents(ctx context.Context) error {
246
201
return nil
247
202
}
248
203
249
- func (col * Collector ) execute (ctx context.Context ) error {
204
+ // Run starts the collector according to the given configuration given, and waits for it to complete.
205
+ // Consecutive calls to Run are not allowed, Run shouldn't be called once a collector is shut down.
206
+ func (col * Collector ) Run (ctx context.Context ) error {
250
207
col .zPagesSpanProcessor = zpages .NewSpanProcessor ()
251
208
col .tracerProvider = sdktrace .NewTracerProvider (
252
209
sdktrace .WithSampler (internal .AlwaysRecord ()),
0 commit comments