| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package connector |
| 5 |
|
| 6 |
import ( |
| 7 |
"context" |
| 8 |
|
| 9 |
"go.opentelemetry.io/collector/component" |
| 10 |
"go.opentelemetry.io/collector/connector/internal" |
| 11 |
"go.opentelemetry.io/collector/consumer" |
| 12 |
"go.opentelemetry.io/collector/pipeline" |
| 13 |
) |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
type Traces interface { |
| 28 |
component.Component |
| 29 |
consumer.Traces |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
type Metrics interface { |
| 44 |
component.Component |
| 45 |
consumer.Metrics |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
type Logs interface { |
| 59 |
component.Component |
| 60 |
consumer.Logs |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
type Settings struct { |
| 65 |
|
| 66 |
ID component.ID |
| 67 |
|
| 68 |
component.TelemetrySettings |
| 69 |
|
| 70 |
|
| 71 |
BuildInfo component.BuildInfo |
| 72 |
|
| 73 |
_ struct{} |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
type Factory interface { |
| 81 |
component.Factory |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
CreateDefaultConfig() component.Config |
| 91 |
|
| 92 |
CreateTracesToTraces(ctx context.Context, set Settings, cfg component.Config, next consumer.Traces) (Traces, error) |
| 93 |
CreateTracesToMetrics(ctx context.Context, set Settings, cfg component.Config, next consumer.Metrics) (Traces, error) |
| 94 |
CreateTracesToLogs(ctx context.Context, set Settings, cfg component.Config, next consumer.Logs) (Traces, error) |
| 95 |
|
| 96 |
CreateMetricsToTraces(ctx context.Context, set Settings, cfg component.Config, next consumer.Traces) (Metrics, error) |
| 97 |
CreateMetricsToMetrics(ctx context.Context, set Settings, cfg component.Config, next consumer.Metrics) (Metrics, error) |
| 98 |
CreateMetricsToLogs(ctx context.Context, set Settings, cfg component.Config, next consumer.Logs) (Metrics, error) |
| 99 |
|
| 100 |
CreateLogsToTraces(ctx context.Context, set Settings, cfg component.Config, next consumer.Traces) (Logs, error) |
| 101 |
CreateLogsToMetrics(ctx context.Context, set Settings, cfg component.Config, next consumer.Metrics) (Logs, error) |
| 102 |
CreateLogsToLogs(ctx context.Context, set Settings, cfg component.Config, next consumer.Logs) (Logs, error) |
| 103 |
|
| 104 |
TracesToTracesStability() component.StabilityLevel |
| 105 |
TracesToMetricsStability() component.StabilityLevel |
| 106 |
TracesToLogsStability() component.StabilityLevel |
| 107 |
|
| 108 |
MetricsToTracesStability() component.StabilityLevel |
| 109 |
MetricsToMetricsStability() component.StabilityLevel |
| 110 |
MetricsToLogsStability() component.StabilityLevel |
| 111 |
|
| 112 |
LogsToTracesStability() component.StabilityLevel |
| 113 |
LogsToMetricsStability() component.StabilityLevel |
| 114 |
LogsToLogsStability() component.StabilityLevel |
| 115 |
|
| 116 |
unexportedFactoryFunc() |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
type FactoryOption interface { |
| 121 |
|
| 122 |
apply(o *factory) |
| 123 |
} |
| 124 |
|
| 125 |
var _ FactoryOption = (*factoryOptionFunc)(nil) |
| 126 |
|
| 127 |
|
| 128 |
type factoryOptionFunc func(*factory) |
| 129 |
|
| 130 |
func (f factoryOptionFunc) apply(o *factory) { |
| 131 |
f(o) |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
type CreateTracesToTracesFunc func(context.Context, Settings, component.Config, consumer.Traces) (Traces, error) |
| 136 |
|
| 137 |
|
| 138 |
type CreateTracesToMetricsFunc func(context.Context, Settings, component.Config, consumer.Metrics) (Traces, error) |
| 139 |
|
| 140 |
|
| 141 |
type CreateTracesToLogsFunc func(context.Context, Settings, component.Config, consumer.Logs) (Traces, error) |
| 142 |
|
| 143 |
|
| 144 |
type CreateMetricsToTracesFunc func(context.Context, Settings, component.Config, consumer.Traces) (Metrics, error) |
| 145 |
|
| 146 |
|
| 147 |
type CreateMetricsToMetricsFunc func(context.Context, Settings, component.Config, consumer.Metrics) (Metrics, error) |
| 148 |
|
| 149 |
|
| 150 |
type CreateMetricsToLogsFunc func(context.Context, Settings, component.Config, consumer.Logs) (Metrics, error) |
| 151 |
|
| 152 |
|
| 153 |
type CreateLogsToTracesFunc func(context.Context, Settings, component.Config, consumer.Traces) (Logs, error) |
| 154 |
|
| 155 |
|
| 156 |
type CreateLogsToMetricsFunc func(context.Context, Settings, component.Config, consumer.Metrics) (Logs, error) |
| 157 |
|
| 158 |
|
| 159 |
type CreateLogsToLogsFunc func(context.Context, Settings, component.Config, consumer.Logs) (Logs, error) |
| 160 |
|
| 161 |
|
| 162 |
func WithTracesToTraces(createTracesToTraces CreateTracesToTracesFunc, sl component.StabilityLevel) FactoryOption { |
| 163 |
return factoryOptionFunc(func(o *factory) { |
| 164 |
o.tracesToTracesStabilityLevel = sl |
| 165 |
o.createTracesToTracesFunc = createTracesToTraces |
| 166 |
}) |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
func WithTracesToMetrics(createTracesToMetrics CreateTracesToMetricsFunc, sl component.StabilityLevel) FactoryOption { |
| 171 |
return factoryOptionFunc(func(o *factory) { |
| 172 |
o.tracesToMetricsStabilityLevel = sl |
| 173 |
o.createTracesToMetricsFunc = createTracesToMetrics |
| 174 |
}) |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
func WithTracesToLogs(createTracesToLogs CreateTracesToLogsFunc, sl component.StabilityLevel) FactoryOption { |
| 179 |
return factoryOptionFunc(func(o *factory) { |
| 180 |
o.tracesToLogsStabilityLevel = sl |
| 181 |
o.createTracesToLogsFunc = createTracesToLogs |
| 182 |
}) |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
func WithMetricsToTraces(createMetricsToTraces CreateMetricsToTracesFunc, sl component.StabilityLevel) FactoryOption { |
| 187 |
return factoryOptionFunc(func(o *factory) { |
| 188 |
o.metricsToTracesStabilityLevel = sl |
| 189 |
o.createMetricsToTracesFunc = createMetricsToTraces |
| 190 |
}) |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
func WithMetricsToMetrics(createMetricsToMetrics CreateMetricsToMetricsFunc, sl component.StabilityLevel) FactoryOption { |
| 195 |
return factoryOptionFunc(func(o *factory) { |
| 196 |
o.metricsToMetricsStabilityLevel = sl |
| 197 |
o.createMetricsToMetricsFunc = createMetricsToMetrics |
| 198 |
}) |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
func WithMetricsToLogs(createMetricsToLogs CreateMetricsToLogsFunc, sl component.StabilityLevel) FactoryOption { |
| 203 |
return factoryOptionFunc(func(o *factory) { |
| 204 |
o.metricsToLogsStabilityLevel = sl |
| 205 |
o.createMetricsToLogsFunc = createMetricsToLogs |
| 206 |
}) |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
func WithLogsToTraces(createLogsToTraces CreateLogsToTracesFunc, sl component.StabilityLevel) FactoryOption { |
| 211 |
return factoryOptionFunc(func(o *factory) { |
| 212 |
o.logsToTracesStabilityLevel = sl |
| 213 |
o.createLogsToTracesFunc = createLogsToTraces |
| 214 |
}) |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
func WithLogsToMetrics(createLogsToMetrics CreateLogsToMetricsFunc, sl component.StabilityLevel) FactoryOption { |
| 219 |
return factoryOptionFunc(func(o *factory) { |
| 220 |
o.logsToMetricsStabilityLevel = sl |
| 221 |
o.createLogsToMetricsFunc = createLogsToMetrics |
| 222 |
}) |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
func WithLogsToLogs(createLogsToLogs CreateLogsToLogsFunc, sl component.StabilityLevel) FactoryOption { |
| 227 |
return factoryOptionFunc(func(o *factory) { |
| 228 |
o.logsToLogsStabilityLevel = sl |
| 229 |
o.createLogsToLogsFunc = createLogsToLogs |
| 230 |
}) |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
type factory struct { |
| 235 |
cfgType component.Type |
| 236 |
component.CreateDefaultConfigFunc |
| 237 |
|
| 238 |
createTracesToTracesFunc CreateTracesToTracesFunc |
| 239 |
createTracesToMetricsFunc CreateTracesToMetricsFunc |
| 240 |
createTracesToLogsFunc CreateTracesToLogsFunc |
| 241 |
|
| 242 |
createMetricsToTracesFunc CreateMetricsToTracesFunc |
| 243 |
createMetricsToMetricsFunc CreateMetricsToMetricsFunc |
| 244 |
createMetricsToLogsFunc CreateMetricsToLogsFunc |
| 245 |
|
| 246 |
createLogsToTracesFunc CreateLogsToTracesFunc |
| 247 |
createLogsToMetricsFunc CreateLogsToMetricsFunc |
| 248 |
createLogsToLogsFunc CreateLogsToLogsFunc |
| 249 |
|
| 250 |
tracesToTracesStabilityLevel component.StabilityLevel |
| 251 |
tracesToMetricsStabilityLevel component.StabilityLevel |
| 252 |
tracesToLogsStabilityLevel component.StabilityLevel |
| 253 |
|
| 254 |
metricsToTracesStabilityLevel component.StabilityLevel |
| 255 |
metricsToMetricsStabilityLevel component.StabilityLevel |
| 256 |
metricsToLogsStabilityLevel component.StabilityLevel |
| 257 |
|
| 258 |
logsToTracesStabilityLevel component.StabilityLevel |
| 259 |
logsToMetricsStabilityLevel component.StabilityLevel |
| 260 |
logsToLogsStabilityLevel component.StabilityLevel |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
func (f *factory) Type() component.Type { |
| 265 |
return f.cfgType |
| 266 |
} |
| 267 |
|
| 268 |
func (f *factory) unexportedFactoryFunc() {} |
| 269 |
|
| 270 |
func (f *factory) TracesToTracesStability() component.StabilityLevel { |
| 271 |
return f.tracesToTracesStabilityLevel |
| 272 |
} |
| 273 |
|
| 274 |
func (f *factory) TracesToMetricsStability() component.StabilityLevel { |
| 275 |
return f.tracesToMetricsStabilityLevel |
| 276 |
} |
| 277 |
|
| 278 |
func (f *factory) TracesToLogsStability() component.StabilityLevel { |
| 279 |
return f.tracesToLogsStabilityLevel |
| 280 |
} |
| 281 |
|
| 282 |
func (f *factory) MetricsToTracesStability() component.StabilityLevel { |
| 283 |
return f.metricsToTracesStabilityLevel |
| 284 |
} |
| 285 |
|
| 286 |
func (f *factory) MetricsToMetricsStability() component.StabilityLevel { |
| 287 |
return f.metricsToMetricsStabilityLevel |
| 288 |
} |
| 289 |
|
| 290 |
func (f *factory) MetricsToLogsStability() component.StabilityLevel { |
| 291 |
return f.metricsToLogsStabilityLevel |
| 292 |
} |
| 293 |
|
| 294 |
func (f *factory) LogsToTracesStability() component.StabilityLevel { |
| 295 |
return f.logsToTracesStabilityLevel |
| 296 |
} |
| 297 |
|
| 298 |
func (f *factory) LogsToMetricsStability() component.StabilityLevel { |
| 299 |
return f.logsToMetricsStabilityLevel |
| 300 |
} |
| 301 |
|
| 302 |
func (f *factory) LogsToLogsStability() component.StabilityLevel { |
| 303 |
return f.logsToLogsStabilityLevel |
| 304 |
} |
| 305 |
|
| 306 |
func (f *factory) CreateTracesToTraces(ctx context.Context, set Settings, cfg component.Config, next consumer.Traces) (Traces, error) { |
| 307 |
if f.createTracesToTracesFunc == nil { |
| 308 |
return nil, internal.ErrDataTypes(set.ID, pipeline.SignalTraces, pipeline.SignalTraces) |
| 309 |
} |
| 310 |
|
| 311 |
if set.ID.Type() != f.Type() { |
| 312 |
return nil, internal.ErrIDMismatch(set.ID, f.Type()) |
| 313 |
} |
| 314 |
|
| 315 |
return f.createTracesToTracesFunc(ctx, set, cfg, next) |
| 316 |
} |
| 317 |
|
| 318 |
func (f *factory) CreateTracesToMetrics(ctx context.Context, set Settings, cfg component.Config, next consumer.Metrics) (Traces, error) { |
| 319 |
if f.createTracesToMetricsFunc == nil { |
| 320 |
return nil, internal.ErrDataTypes(set.ID, pipeline.SignalTraces, pipeline.SignalMetrics) |
| 321 |
} |
| 322 |
|
| 323 |
if set.ID.Type() != f.Type() { |
| 324 |
return nil, internal.ErrIDMismatch(set.ID, f.Type()) |
| 325 |
} |
| 326 |
|
| 327 |
return f.createTracesToMetricsFunc(ctx, set, cfg, next) |
| 328 |
} |
| 329 |
|
| 330 |
func (f *factory) CreateTracesToLogs(ctx context.Context, set Settings, cfg component.Config, next consumer.Logs) (Traces, error) { |
| 331 |
if f.createTracesToLogsFunc == nil { |
| 332 |
return nil, internal.ErrDataTypes(set.ID, pipeline.SignalTraces, pipeline.SignalLogs) |
| 333 |
} |
| 334 |
|
| 335 |
if set.ID.Type() != f.Type() { |
| 336 |
return nil, internal.ErrIDMismatch(set.ID, f.Type()) |
| 337 |
} |
| 338 |
|
| 339 |
return f.createTracesToLogsFunc(ctx, set, cfg, next) |
| 340 |
} |
| 341 |
|
| 342 |
func (f *factory) CreateMetricsToTraces(ctx context.Context, set Settings, cfg component.Config, next consumer.Traces) (Metrics, error) { |
| 343 |
if f.createMetricsToTracesFunc == nil { |
| 344 |
return nil, internal.ErrDataTypes(set.ID, pipeline.SignalMetrics, pipeline.SignalTraces) |
| 345 |
} |
| 346 |
|
| 347 |
if set.ID.Type() != f.Type() { |
| 348 |
return nil, internal.ErrIDMismatch(set.ID, f.Type()) |
| 349 |
} |
| 350 |
|
| 351 |
return f.createMetricsToTracesFunc(ctx, set, cfg, next) |
| 352 |
} |
| 353 |
|
| 354 |
func (f *factory) CreateMetricsToMetrics(ctx context.Context, set Settings, cfg component.Config, next consumer.Metrics) (Metrics, error) { |
| 355 |
if f.createMetricsToMetricsFunc == nil { |
| 356 |
return nil, internal.ErrDataTypes(set.ID, pipeline.SignalMetrics, pipeline.SignalMetrics) |
| 357 |
} |
| 358 |
|
| 359 |
if set.ID.Type() != f.Type() { |
| 360 |
return nil, internal.ErrIDMismatch(set.ID, f.Type()) |
| 361 |
} |
| 362 |
|
| 363 |
return f.createMetricsToMetricsFunc(ctx, set, cfg, next) |
| 364 |
} |
| 365 |
|
| 366 |
func (f *factory) CreateMetricsToLogs(ctx context.Context, set Settings, cfg component.Config, next consumer.Logs) (Metrics, error) { |
| 367 |
if f.createMetricsToLogsFunc == nil { |
| 368 |
return nil, internal.ErrDataTypes(set.ID, pipeline.SignalMetrics, pipeline.SignalLogs) |
| 369 |
} |
| 370 |
|
| 371 |
if set.ID.Type() != f.Type() { |
| 372 |
return nil, internal.ErrIDMismatch(set.ID, f.Type()) |
| 373 |
} |
| 374 |
|
| 375 |
return f.createMetricsToLogsFunc(ctx, set, cfg, next) |
| 376 |
} |
| 377 |
|
| 378 |
func (f *factory) CreateLogsToTraces(ctx context.Context, set Settings, cfg component.Config, next consumer.Traces) (Logs, error) { |
| 379 |
if f.createLogsToTracesFunc == nil { |
| 380 |
return nil, internal.ErrDataTypes(set.ID, pipeline.SignalLogs, pipeline.SignalTraces) |
| 381 |
} |
| 382 |
|
| 383 |
if set.ID.Type() != f.Type() { |
| 384 |
return nil, internal.ErrIDMismatch(set.ID, f.Type()) |
| 385 |
} |
| 386 |
|
| 387 |
return f.createLogsToTracesFunc(ctx, set, cfg, next) |
| 388 |
} |
| 389 |
|
| 390 |
func (f *factory) CreateLogsToMetrics(ctx context.Context, set Settings, cfg component.Config, next consumer.Metrics) (Logs, error) { |
| 391 |
if f.createLogsToMetricsFunc == nil { |
| 392 |
return nil, internal.ErrDataTypes(set.ID, pipeline.SignalLogs, pipeline.SignalMetrics) |
| 393 |
} |
| 394 |
|
| 395 |
if set.ID.Type() != f.Type() { |
| 396 |
return nil, internal.ErrIDMismatch(set.ID, f.Type()) |
| 397 |
} |
| 398 |
|
| 399 |
return f.createLogsToMetricsFunc(ctx, set, cfg, next) |
| 400 |
} |
| 401 |
|
| 402 |
func (f *factory) CreateLogsToLogs(ctx context.Context, set Settings, cfg component.Config, next consumer.Logs) (Logs, error) { |
| 403 |
if f.createLogsToLogsFunc == nil { |
| 404 |
return nil, internal.ErrDataTypes(set.ID, pipeline.SignalLogs, pipeline.SignalLogs) |
| 405 |
} |
| 406 |
|
| 407 |
if set.ID.Type() != f.Type() { |
| 408 |
return nil, internal.ErrIDMismatch(set.ID, f.Type()) |
| 409 |
} |
| 410 |
|
| 411 |
return f.createLogsToLogsFunc(ctx, set, cfg, next) |
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
func NewFactory(cfgType component.Type, createDefaultConfig component.CreateDefaultConfigFunc, options ...FactoryOption) Factory { |
| 416 |
f := &factory{ |
| 417 |
cfgType: cfgType, |
| 418 |
CreateDefaultConfigFunc: createDefaultConfig, |
| 419 |
} |
| 420 |
for _, opt := range options { |
| 421 |
opt.apply(f) |
| 422 |
} |
| 423 |
return f |
| 424 |
} |