| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package graph |
| 5 |
|
| 6 |
import ( |
| 7 |
"context" |
| 8 |
"testing" |
| 9 |
|
| 10 |
"github.com/stretchr/testify/assert" |
| 11 |
"github.com/stretchr/testify/require" |
| 12 |
"go.opentelemetry.io/otel/attribute" |
| 13 |
"go.opentelemetry.io/otel/sdk/metric/metricdata" |
| 14 |
|
| 15 |
"go.opentelemetry.io/collector/component" |
| 16 |
"go.opentelemetry.io/collector/component/componenttest" |
| 17 |
"go.opentelemetry.io/collector/connector" |
| 18 |
"go.opentelemetry.io/collector/exporter" |
| 19 |
"go.opentelemetry.io/collector/pdata/testdata" |
| 20 |
"go.opentelemetry.io/collector/pipeline" |
| 21 |
"go.opentelemetry.io/collector/pipeline/xpipeline" |
| 22 |
"go.opentelemetry.io/collector/processor" |
| 23 |
"go.opentelemetry.io/collector/receiver" |
| 24 |
"go.opentelemetry.io/collector/service/internal/builders" |
| 25 |
"go.opentelemetry.io/collector/service/internal/obsconsumer" |
| 26 |
"go.opentelemetry.io/collector/service/internal/testcomponents" |
| 27 |
"go.opentelemetry.io/collector/service/pipelines" |
| 28 |
) |
| 29 |
|
| 30 |
func TestComponentInstrumentation(t *testing.T) { |
| 31 |
setObsConsumerGateForTest(t, true) |
| 32 |
// All IDs have a name to ensure the "otelcol.component.id" attribute is not just the type |
| 33 |
rcvrID := component.MustNewIDWithName("examplereceiver", "foo") |
| 34 |
procID := component.MustNewIDWithName("exampleprocessor", "bar") |
| 35 |
routerID := component.MustNewIDWithName("examplerouter", "baz") |
| 36 |
expRightID := component.MustNewIDWithName("exampleexporter", "right") |
| 37 |
expLeftID := component.MustNewIDWithName("exampleexporter", "left") |
| 38 |
|
| 39 |
tracesInID := pipeline.NewIDWithName(pipeline.SignalTraces, "in") |
| 40 |
tracesRightID := pipeline.NewIDWithName(pipeline.SignalTraces, "right") |
| 41 |
tracesLeftID := pipeline.NewIDWithName(pipeline.SignalTraces, "left") |
| 42 |
|
| 43 |
metricsInID := pipeline.NewIDWithName(pipeline.SignalMetrics, "in") |
| 44 |
metricsRightID := pipeline.NewIDWithName(pipeline.SignalMetrics, "right") |
| 45 |
metricsLeftID := pipeline.NewIDWithName(pipeline.SignalMetrics, "left") |
| 46 |
|
| 47 |
logsInID := pipeline.NewIDWithName(pipeline.SignalLogs, "in") |
| 48 |
logsRightID := pipeline.NewIDWithName(pipeline.SignalLogs, "right") |
| 49 |
logsLeftID := pipeline.NewIDWithName(pipeline.SignalLogs, "left") |
| 50 |
|
| 51 |
profilesInID := pipeline.NewIDWithName(xpipeline.SignalProfiles, "in") |
| 52 |
profilesRightID := pipeline.NewIDWithName(xpipeline.SignalProfiles, "right") |
| 53 |
profilesLeftID := pipeline.NewIDWithName(xpipeline.SignalProfiles, "left") |
| 54 |
|
| 55 |
ctx := context.Background() |
| 56 |
testTel := componenttest.NewTelemetry() |
| 57 |
set := Settings{ |
| 58 |
Telemetry: testTel.NewTelemetrySettings(), |
| 59 |
BuildInfo: component.NewDefaultBuildInfo(), |
| 60 |
ReceiverBuilder: builders.NewReceiver( |
| 61 |
map[component.ID]component.Config{ |
| 62 |
rcvrID: testcomponents.ExampleReceiverFactory.CreateDefaultConfig(), |
| 63 |
}, |
| 64 |
map[component.Type]receiver.Factory{ |
| 65 |
testcomponents.ExampleReceiverFactory.Type(): testcomponents.ExampleReceiverFactory, |
| 66 |
}, |
| 67 |
), |
| 68 |
ProcessorBuilder: builders.NewProcessor( |
| 69 |
map[component.ID]component.Config{ |
| 70 |
procID: testcomponents.ExampleProcessorFactory.CreateDefaultConfig(), |
| 71 |
}, |
| 72 |
map[component.Type]processor.Factory{ |
| 73 |
testcomponents.ExampleProcessorFactory.Type(): testcomponents.ExampleProcessorFactory, |
| 74 |
}, |
| 75 |
), |
| 76 |
ExporterBuilder: builders.NewExporter( |
| 77 |
map[component.ID]component.Config{ |
| 78 |
expRightID: testcomponents.ExampleExporterFactory.CreateDefaultConfig(), |
| 79 |
expLeftID: testcomponents.ExampleExporterFactory.CreateDefaultConfig(), |
| 80 |
}, |
| 81 |
map[component.Type]exporter.Factory{ |
| 82 |
testcomponents.ExampleExporterFactory.Type(): testcomponents.ExampleExporterFactory, |
| 83 |
}, |
| 84 |
), |
| 85 |
ConnectorBuilder: builders.NewConnector( |
| 86 |
map[component.ID]component.Config{ |
| 87 |
routerID: testcomponents.ExampleRouterConfig{ |
| 88 |
Traces: &testcomponents.LeftRightConfig{ |
| 89 |
Right: tracesRightID, |
| 90 |
Left: tracesLeftID, |
| 91 |
}, |
| 92 |
Metrics: &testcomponents.LeftRightConfig{ |
| 93 |
Right: metricsRightID, |
| 94 |
Left: metricsLeftID, |
| 95 |
}, |
| 96 |
Logs: &testcomponents.LeftRightConfig{ |
| 97 |
Right: logsRightID, |
| 98 |
Left: logsLeftID, |
| 99 |
}, |
| 100 |
Profiles: &testcomponents.LeftRightConfig{ |
| 101 |
Right: profilesRightID, |
| 102 |
Left: profilesLeftID, |
| 103 |
}, |
| 104 |
}, |
| 105 |
}, |
| 106 |
map[component.Type]connector.Factory{ |
| 107 |
testcomponents.ExampleRouterFactory.Type(): testcomponents.ExampleRouterFactory, |
| 108 |
}, |
| 109 |
), |
| 110 |
PipelineConfigs: pipelines.Config{ |
| 111 |
tracesInID: { |
| 112 |
Receivers: []component.ID{rcvrID}, |
| 113 |
Processors: []component.ID{procID}, |
| 114 |
Exporters: []component.ID{routerID}, |
| 115 |
}, |
| 116 |
tracesRightID: { |
| 117 |
Receivers: []component.ID{routerID}, |
| 118 |
Exporters: []component.ID{expRightID}, |
| 119 |
}, |
| 120 |
tracesLeftID: { |
| 121 |
Receivers: []component.ID{routerID}, |
| 122 |
Exporters: []component.ID{expLeftID}, |
| 123 |
}, |
| 124 |
metricsInID: { |
| 125 |
Receivers: []component.ID{rcvrID}, |
| 126 |
Processors: []component.ID{procID}, |
| 127 |
Exporters: []component.ID{routerID}, |
| 128 |
}, |
| 129 |
metricsRightID: { |
| 130 |
Receivers: []component.ID{routerID}, |
| 131 |
Exporters: []component.ID{expRightID}, |
| 132 |
}, |
| 133 |
metricsLeftID: { |
| 134 |
Receivers: []component.ID{routerID}, |
| 135 |
Exporters: []component.ID{expLeftID}, |
| 136 |
}, |
| 137 |
logsInID: { |
| 138 |
Receivers: []component.ID{rcvrID}, |
| 139 |
Processors: []component.ID{procID}, |
| 140 |
Exporters: []component.ID{routerID}, |
| 141 |
}, |
| 142 |
logsRightID: { |
| 143 |
Receivers: []component.ID{routerID}, |
| 144 |
Exporters: []component.ID{expRightID}, |
| 145 |
}, |
| 146 |
logsLeftID: { |
| 147 |
Receivers: []component.ID{routerID}, |
| 148 |
Exporters: []component.ID{expLeftID}, |
| 149 |
}, |
| 150 |
profilesInID: { |
| 151 |
Receivers: []component.ID{rcvrID}, |
| 152 |
Processors: []component.ID{procID}, |
| 153 |
Exporters: []component.ID{routerID}, |
| 154 |
}, |
| 155 |
profilesRightID: { |
| 156 |
Receivers: []component.ID{routerID}, |
| 157 |
Exporters: []component.ID{expRightID}, |
| 158 |
}, |
| 159 |
profilesLeftID: { |
| 160 |
Receivers: []component.ID{routerID}, |
| 161 |
Exporters: []component.ID{expLeftID}, |
| 162 |
}, |
| 163 |
}, |
| 164 |
} |
| 165 |
|
| 166 |
pg, err := Build(ctx, set) |
| 167 |
require.NoError(t, err) |
| 168 |
|
| 169 |
allReceivers := pg.getReceivers() |
| 170 |
|
| 171 |
assert.Len(t, pg.pipelines, len(set.PipelineConfigs)) |
| 172 |
|
| 173 |
// First 3 right, next 2 left |
| 174 |
tracesReceiver := allReceivers[pipeline.SignalTraces][rcvrID].(*testcomponents.ExampleReceiver) |
| 175 |
require.NoError(t, tracesReceiver.ConsumeTraces(ctx, testdata.GenerateTraces(3))) |
| 176 |
require.NoError(t, tracesReceiver.ConsumeTraces(ctx, testdata.GenerateTraces(2))) |
| 177 |
|
| 178 |
// First 5 right, next 4 left |
| 179 |
metricsReceiver := allReceivers[pipeline.SignalMetrics][rcvrID].(*testcomponents.ExampleReceiver) |
| 180 |
require.NoError(t, metricsReceiver.ConsumeMetrics(ctx, testdata.GenerateMetrics(5))) |
| 181 |
require.NoError(t, metricsReceiver.ConsumeMetrics(ctx, testdata.GenerateMetrics(4))) |
| 182 |
|
| 183 |
// First 7 right, next 6 left |
| 184 |
logsReceiver := allReceivers[pipeline.SignalLogs][rcvrID].(*testcomponents.ExampleReceiver) |
| 185 |
require.NoError(t, logsReceiver.ConsumeLogs(ctx, testdata.GenerateLogs(7))) |
| 186 |
require.NoError(t, logsReceiver.ConsumeLogs(ctx, testdata.GenerateLogs(6))) |
| 187 |
|
| 188 |
// First 9 right, next 8 left |
| 189 |
profilesReceiver := allReceivers[xpipeline.SignalProfiles][rcvrID].(*testcomponents.ExampleReceiver) |
| 190 |
require.NoError(t, profilesReceiver.ConsumeProfiles(ctx, testdata.GenerateProfiles(9))) |
| 191 |
require.NoError(t, profilesReceiver.ConsumeProfiles(ctx, testdata.GenerateProfiles(8))) |
| 192 |
|
| 193 |
// TODO fix metric name prefix delimiter |
| 194 |
expectedScopeMetrics := simpleScopeMetrics{ |
| 195 |
// Traces |
| 196 |
attribute.NewSet( |
| 197 |
attribute.String("otelcol.component.kind", "receiver"), |
| 198 |
attribute.String("otelcol.component.id", "examplereceiver/foo"), |
| 199 |
attribute.String("otelcol.signal", "traces"), |
| 200 |
): simpleMetricMap{ |
| 201 |
"otelcol.receiver.produced.items": simpleMetric{ |
| 202 |
attribute.NewSet( |
| 203 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 204 |
): 5, |
| 205 |
}, |
| 206 |
"otelcol.receiver.produced.size": simpleMetric{ |
| 207 |
attribute.NewSet( |
| 208 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 209 |
): 866, |
| 210 |
}, |
| 211 |
}, |
| 212 |
attribute.NewSet( |
| 213 |
attribute.String("otelcol.component.kind", "processor"), |
| 214 |
attribute.String("otelcol.component.id", "exampleprocessor/bar"), |
| 215 |
attribute.String("otelcol.pipeline.id", "traces/in"), |
| 216 |
attribute.String("otelcol.signal", "traces"), |
| 217 |
): simpleMetricMap{ |
| 218 |
"otelcol.processor.consumed.items": simpleMetric{ |
| 219 |
attribute.NewSet( |
| 220 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 221 |
): 5, |
| 222 |
}, |
| 223 |
"otelcol.processor.produced.items": simpleMetric{ |
| 224 |
attribute.NewSet( |
| 225 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 226 |
): 5, |
| 227 |
}, |
| 228 |
"otelcol.processor.consumed.size": simpleMetric{ |
| 229 |
attribute.NewSet( |
| 230 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 231 |
): 866, |
| 232 |
}, |
| 233 |
"otelcol.processor.produced.size": simpleMetric{ |
| 234 |
attribute.NewSet( |
| 235 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 236 |
): 866, |
| 237 |
}, |
| 238 |
}, |
| 239 |
attribute.NewSet( |
| 240 |
attribute.String("otelcol.component.kind", "connector"), |
| 241 |
attribute.String("otelcol.component.id", "examplerouter/baz"), |
| 242 |
attribute.String("otelcol.signal", "traces"), |
| 243 |
attribute.String("otelcol.signal.output", "traces"), |
| 244 |
): simpleMetricMap{ |
| 245 |
"otelcol.connector.consumed.items": simpleMetric{ |
| 246 |
attribute.NewSet( |
| 247 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 248 |
): 5, |
| 249 |
}, |
| 250 |
"otelcol.connector.produced.items": simpleMetric{ |
| 251 |
attribute.NewSet( |
| 252 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 253 |
attribute.String("otelcol.pipeline.id", "traces/right"), |
| 254 |
): 3, |
| 255 |
attribute.NewSet( |
| 256 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 257 |
attribute.String("otelcol.pipeline.id", "traces/left"), |
| 258 |
): 2, |
| 259 |
}, |
| 260 |
"otelcol.connector.consumed.size": simpleMetric{ |
| 261 |
attribute.NewSet( |
| 262 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 263 |
): 866, |
| 264 |
}, |
| 265 |
"otelcol.connector.produced.size": simpleMetric{ |
| 266 |
attribute.NewSet( |
| 267 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 268 |
attribute.String("otelcol.pipeline.id", "traces/right"), |
| 269 |
): 528, |
| 270 |
attribute.NewSet( |
| 271 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 272 |
attribute.String("otelcol.pipeline.id", "traces/left"), |
| 273 |
): 338, |
| 274 |
}, |
| 275 |
}, |
| 276 |
attribute.NewSet( |
| 277 |
attribute.String("otelcol.component.kind", "exporter"), |
| 278 |
attribute.String("otelcol.component.id", "exampleexporter/right"), |
| 279 |
attribute.String("otelcol.signal", "traces"), |
| 280 |
): simpleMetricMap{ |
| 281 |
"otelcol.exporter.consumed.items": simpleMetric{ |
| 282 |
attribute.NewSet( |
| 283 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 284 |
): 3, |
| 285 |
}, |
| 286 |
"otelcol.exporter.consumed.size": simpleMetric{ |
| 287 |
attribute.NewSet( |
| 288 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 289 |
): 528, |
| 290 |
}, |
| 291 |
}, |
| 292 |
attribute.NewSet( |
| 293 |
attribute.String("otelcol.component.kind", "exporter"), |
| 294 |
attribute.String("otelcol.component.id", "exampleexporter/left"), |
| 295 |
attribute.String("otelcol.signal", "traces"), |
| 296 |
): simpleMetricMap{ |
| 297 |
"otelcol.exporter.consumed.items": simpleMetric{ |
| 298 |
attribute.NewSet( |
| 299 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 300 |
): 2, |
| 301 |
}, |
| 302 |
"otelcol.exporter.consumed.size": simpleMetric{ |
| 303 |
attribute.NewSet( |
| 304 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 305 |
): 338, |
| 306 |
}, |
| 307 |
}, |
| 308 |
|
| 309 |
// Metrics |
| 310 |
attribute.NewSet( |
| 311 |
attribute.String("otelcol.component.kind", "receiver"), |
| 312 |
attribute.String("otelcol.component.id", "examplereceiver/foo"), |
| 313 |
attribute.String("otelcol.signal", "metrics"), |
| 314 |
): simpleMetricMap{ |
| 315 |
"otelcol.receiver.produced.items": simpleMetric{ |
| 316 |
attribute.NewSet( |
| 317 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 318 |
): 18, // GenerateMetrics(9) produces 18 data points |
| 319 |
}, |
| 320 |
"otelcol.receiver.produced.size": simpleMetric{ |
| 321 |
attribute.NewSet( |
| 322 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 323 |
): 1741, // GenerateMetrics(9) produces 18 data points |
| 324 |
}, |
| 325 |
}, |
| 326 |
attribute.NewSet( |
| 327 |
attribute.String("otelcol.component.kind", "processor"), |
| 328 |
attribute.String("otelcol.component.id", "exampleprocessor/bar"), |
| 329 |
attribute.String("otelcol.pipeline.id", "metrics/in"), |
| 330 |
attribute.String("otelcol.signal", "metrics"), |
| 331 |
): simpleMetricMap{ |
| 332 |
"otelcol.processor.consumed.items": simpleMetric{ |
| 333 |
attribute.NewSet( |
| 334 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 335 |
): 18, // GenerateMetrics(9) produces 18 data points |
| 336 |
}, |
| 337 |
"otelcol.processor.produced.items": simpleMetric{ |
| 338 |
attribute.NewSet( |
| 339 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 340 |
): 18, // GenerateMetrics(9) produces 18 data points |
| 341 |
}, |
| 342 |
"otelcol.processor.consumed.size": simpleMetric{ |
| 343 |
attribute.NewSet( |
| 344 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 345 |
): 1741, // GenerateMetrics(9) produces 18 data points |
| 346 |
}, |
| 347 |
"otelcol.processor.produced.size": simpleMetric{ |
| 348 |
attribute.NewSet( |
| 349 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 350 |
): 1741, // GenerateMetrics(9) produces 18 data points |
| 351 |
}, |
| 352 |
}, |
| 353 |
attribute.NewSet( |
| 354 |
attribute.String("otelcol.component.kind", "connector"), |
| 355 |
attribute.String("otelcol.component.id", "examplerouter/baz"), |
| 356 |
attribute.String("otelcol.signal", "metrics"), |
| 357 |
attribute.String("otelcol.signal.output", "metrics"), |
| 358 |
): simpleMetricMap{ |
| 359 |
"otelcol.connector.consumed.items": simpleMetric{ |
| 360 |
attribute.NewSet( |
| 361 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 362 |
): 18, // GenerateMetrics(9) produces 18 data points |
| 363 |
}, |
| 364 |
"otelcol.connector.produced.items": simpleMetric{ |
| 365 |
attribute.NewSet( |
| 366 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 367 |
attribute.String("otelcol.pipeline.id", "metrics/right"), |
| 368 |
): 10, // GenerateMetrics(5) produces 10 data points |
| 369 |
attribute.NewSet( |
| 370 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 371 |
attribute.String("otelcol.pipeline.id", "metrics/left"), |
| 372 |
): 8, // GenerateMetrics(4) produces 8 data points |
| 373 |
}, |
| 374 |
"otelcol.connector.consumed.size": simpleMetric{ |
| 375 |
attribute.NewSet( |
| 376 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 377 |
): 1741, // GenerateMetrics(9) produces 18 data points |
| 378 |
}, |
| 379 |
"otelcol.connector.produced.size": simpleMetric{ |
| 380 |
attribute.NewSet( |
| 381 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 382 |
attribute.String("otelcol.pipeline.id", "metrics/right"), |
| 383 |
): 1035, // GenerateMetrics(5) produces 10 data points |
| 384 |
attribute.NewSet( |
| 385 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 386 |
attribute.String("otelcol.pipeline.id", "metrics/left"), |
| 387 |
): 706, // GenerateMetrics(4) produces 8 data points |
| 388 |
}, |
| 389 |
}, |
| 390 |
attribute.NewSet( |
| 391 |
attribute.String("otelcol.component.kind", "exporter"), |
| 392 |
attribute.String("otelcol.component.id", "exampleexporter/right"), |
| 393 |
attribute.String("otelcol.signal", "metrics"), |
| 394 |
): simpleMetricMap{ |
| 395 |
"otelcol.exporter.consumed.items": simpleMetric{ |
| 396 |
attribute.NewSet( |
| 397 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 398 |
): 10, // GenerateMetrics(5) produces 10 data points |
| 399 |
}, |
| 400 |
"otelcol.exporter.consumed.size": simpleMetric{ |
| 401 |
attribute.NewSet( |
| 402 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 403 |
): 1035, // GenerateMetrics(9) produces 18 data points |
| 404 |
}, |
| 405 |
}, |
| 406 |
attribute.NewSet( |
| 407 |
attribute.String("otelcol.component.kind", "exporter"), |
| 408 |
attribute.String("otelcol.component.id", "exampleexporter/left"), |
| 409 |
attribute.String("otelcol.signal", "metrics"), |
| 410 |
): simpleMetricMap{ |
| 411 |
"otelcol.exporter.consumed.items": simpleMetric{ |
| 412 |
attribute.NewSet( |
| 413 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 414 |
): 8, // GenerateMetrics(4) produces 8 data points |
| 415 |
}, |
| 416 |
"otelcol.exporter.consumed.size": simpleMetric{ |
| 417 |
attribute.NewSet( |
| 418 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 419 |
): 706, // GenerateMetrics(9) produces 18 data points |
| 420 |
}, |
| 421 |
}, |
| 422 |
|
| 423 |
// Logs |
| 424 |
attribute.NewSet( |
| 425 |
attribute.String("otelcol.component.kind", "receiver"), |
| 426 |
attribute.String("otelcol.component.id", "examplereceiver/foo"), |
| 427 |
attribute.String("otelcol.signal", "logs"), |
| 428 |
): simpleMetricMap{ |
| 429 |
"otelcol.receiver.produced.items": simpleMetric{ |
| 430 |
attribute.NewSet( |
| 431 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 432 |
): 13, |
| 433 |
}, |
| 434 |
"otelcol.receiver.produced.size": simpleMetric{ |
| 435 |
attribute.NewSet( |
| 436 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 437 |
): 1363, |
| 438 |
}, |
| 439 |
}, |
| 440 |
attribute.NewSet( |
| 441 |
attribute.String("otelcol.component.kind", "processor"), |
| 442 |
attribute.String("otelcol.component.id", "exampleprocessor/bar"), |
| 443 |
attribute.String("otelcol.pipeline.id", "logs/in"), |
| 444 |
attribute.String("otelcol.signal", "logs"), |
| 445 |
): simpleMetricMap{ |
| 446 |
"otelcol.processor.consumed.items": simpleMetric{ |
| 447 |
attribute.NewSet( |
| 448 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 449 |
): 13, |
| 450 |
}, |
| 451 |
"otelcol.processor.produced.items": simpleMetric{ |
| 452 |
attribute.NewSet( |
| 453 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 454 |
): 13, |
| 455 |
}, |
| 456 |
"otelcol.processor.consumed.size": simpleMetric{ |
| 457 |
attribute.NewSet( |
| 458 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 459 |
): 1363, |
| 460 |
}, |
| 461 |
"otelcol.processor.produced.size": simpleMetric{ |
| 462 |
attribute.NewSet( |
| 463 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 464 |
): 1363, |
| 465 |
}, |
| 466 |
}, |
| 467 |
attribute.NewSet( |
| 468 |
attribute.String("otelcol.component.kind", "connector"), |
| 469 |
attribute.String("otelcol.component.id", "examplerouter/baz"), |
| 470 |
attribute.String("otelcol.signal", "logs"), |
| 471 |
attribute.String("otelcol.signal.output", "logs"), |
| 472 |
): simpleMetricMap{ |
| 473 |
"otelcol.connector.consumed.items": simpleMetric{ |
| 474 |
attribute.NewSet( |
| 475 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 476 |
): 13, |
| 477 |
}, |
| 478 |
"otelcol.connector.produced.items": simpleMetric{ |
| 479 |
attribute.NewSet( |
| 480 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 481 |
attribute.String("otelcol.pipeline.id", "logs/right"), |
| 482 |
): 7, |
| 483 |
attribute.NewSet( |
| 484 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 485 |
attribute.String("otelcol.pipeline.id", "logs/left"), |
| 486 |
): 6, |
| 487 |
}, |
| 488 |
"otelcol.connector.consumed.size": simpleMetric{ |
| 489 |
attribute.NewSet( |
| 490 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 491 |
): 1363, |
| 492 |
}, |
| 493 |
"otelcol.connector.produced.size": simpleMetric{ |
| 494 |
attribute.NewSet( |
| 495 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 496 |
attribute.String("otelcol.pipeline.id", "logs/right"), |
| 497 |
): 737, |
| 498 |
attribute.NewSet( |
| 499 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 500 |
attribute.String("otelcol.pipeline.id", "logs/left"), |
| 501 |
): 626, |
| 502 |
}, |
| 503 |
}, |
| 504 |
attribute.NewSet( |
| 505 |
attribute.String("otelcol.component.kind", "exporter"), |
| 506 |
attribute.String("otelcol.component.id", "exampleexporter/right"), |
| 507 |
attribute.String("otelcol.signal", "logs"), |
| 508 |
): simpleMetricMap{ |
| 509 |
"otelcol.exporter.consumed.items": simpleMetric{ |
| 510 |
attribute.NewSet( |
| 511 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 512 |
): 7, |
| 513 |
}, |
| 514 |
"otelcol.exporter.consumed.size": simpleMetric{ |
| 515 |
attribute.NewSet( |
| 516 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 517 |
): 737, |
| 518 |
}, |
| 519 |
}, |
| 520 |
attribute.NewSet( |
| 521 |
attribute.String("otelcol.component.kind", "exporter"), |
| 522 |
attribute.String("otelcol.component.id", "exampleexporter/left"), |
| 523 |
attribute.String("otelcol.signal", "logs"), |
| 524 |
): simpleMetricMap{ |
| 525 |
"otelcol.exporter.consumed.items": simpleMetric{ |
| 526 |
attribute.NewSet( |
| 527 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 528 |
): 6, |
| 529 |
}, |
| 530 |
"otelcol.exporter.consumed.size": simpleMetric{ |
| 531 |
attribute.NewSet( |
| 532 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 533 |
): 626, |
| 534 |
}, |
| 535 |
}, |
| 536 |
|
| 537 |
// Profiles |
| 538 |
attribute.NewSet( |
| 539 |
attribute.String("otelcol.component.kind", "receiver"), |
| 540 |
attribute.String("otelcol.component.id", "examplereceiver/foo"), |
| 541 |
attribute.String("otelcol.signal", "profiles"), |
| 542 |
): simpleMetricMap{ |
| 543 |
"otelcol.receiver.produced.items": simpleMetric{ |
| 544 |
attribute.NewSet( |
| 545 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 546 |
): 17, |
| 547 |
}, |
| 548 |
"otelcol.receiver.produced.size": simpleMetric{ |
| 549 |
attribute.NewSet( |
| 550 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 551 |
): 1118, |
| 552 |
}, |
| 553 |
}, |
| 554 |
attribute.NewSet( |
| 555 |
attribute.String("otelcol.component.kind", "processor"), |
| 556 |
attribute.String("otelcol.component.id", "exampleprocessor/bar"), |
| 557 |
attribute.String("otelcol.pipeline.id", "profiles/in"), |
| 558 |
attribute.String("otelcol.signal", "profiles"), |
| 559 |
): simpleMetricMap{ |
| 560 |
"otelcol.processor.consumed.items": simpleMetric{ |
| 561 |
attribute.NewSet( |
| 562 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 563 |
): 17, |
| 564 |
}, |
| 565 |
"otelcol.processor.produced.items": simpleMetric{ |
| 566 |
attribute.NewSet( |
| 567 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 568 |
): 17, |
| 569 |
}, |
| 570 |
"otelcol.processor.consumed.size": simpleMetric{ |
| 571 |
attribute.NewSet( |
| 572 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 573 |
): 1118, |
| 574 |
}, |
| 575 |
"otelcol.processor.produced.size": simpleMetric{ |
| 576 |
attribute.NewSet( |
| 577 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 578 |
): 1118, |
| 579 |
}, |
| 580 |
}, |
| 581 |
attribute.NewSet( |
| 582 |
attribute.String("otelcol.component.kind", "connector"), |
| 583 |
attribute.String("otelcol.component.id", "examplerouter/baz"), |
| 584 |
attribute.String("otelcol.signal", "profiles"), |
| 585 |
attribute.String("otelcol.signal.output", "profiles"), |
| 586 |
): simpleMetricMap{ |
| 587 |
"otelcol.connector.consumed.items": simpleMetric{ |
| 588 |
attribute.NewSet( |
| 589 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 590 |
): 17, |
| 591 |
}, |
| 592 |
"otelcol.connector.produced.items": simpleMetric{ |
| 593 |
attribute.NewSet( |
| 594 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 595 |
attribute.String("otelcol.pipeline.id", "profiles/right"), |
| 596 |
): 9, |
| 597 |
attribute.NewSet( |
| 598 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 599 |
attribute.String("otelcol.pipeline.id", "profiles/left"), |
| 600 |
): 8, |
| 601 |
}, |
| 602 |
"otelcol.connector.consumed.size": simpleMetric{ |
| 603 |
attribute.NewSet( |
| 604 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 605 |
): 1118, |
| 606 |
}, |
| 607 |
"otelcol.connector.produced.size": simpleMetric{ |
| 608 |
attribute.NewSet( |
| 609 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 610 |
attribute.String("otelcol.pipeline.id", "profiles/right"), |
| 611 |
): 587, |
| 612 |
attribute.NewSet( |
| 613 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 614 |
attribute.String("otelcol.pipeline.id", "profiles/left"), |
| 615 |
): 531, |
| 616 |
}, |
| 617 |
}, |
| 618 |
attribute.NewSet( |
| 619 |
attribute.String("otelcol.component.kind", "exporter"), |
| 620 |
attribute.String("otelcol.component.id", "exampleexporter/right"), |
| 621 |
attribute.String("otelcol.signal", "profiles"), |
| 622 |
): simpleMetricMap{ |
| 623 |
"otelcol.exporter.consumed.items": simpleMetric{ |
| 624 |
attribute.NewSet( |
| 625 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 626 |
): 9, |
| 627 |
}, |
| 628 |
"otelcol.exporter.consumed.size": simpleMetric{ |
| 629 |
attribute.NewSet( |
| 630 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 631 |
): 587, |
| 632 |
}, |
| 633 |
}, |
| 634 |
attribute.NewSet( |
| 635 |
attribute.String("otelcol.component.kind", "exporter"), |
| 636 |
attribute.String("otelcol.component.id", "exampleexporter/left"), |
| 637 |
attribute.String("otelcol.signal", "profiles"), |
| 638 |
): simpleMetricMap{ |
| 639 |
"otelcol.exporter.consumed.items": simpleMetric{ |
| 640 |
attribute.NewSet( |
| 641 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 642 |
): 8, |
| 643 |
}, |
| 644 |
"otelcol.exporter.consumed.size": simpleMetric{ |
| 645 |
attribute.NewSet( |
| 646 |
attribute.String(obsconsumer.ComponentOutcome, "success"), |
| 647 |
): 531, |
| 648 |
}, |
| 649 |
}, |
| 650 |
} |
| 651 |
|
| 652 |
// Verify telemetry was properly emitted by components |
| 653 |
var rm metricdata.ResourceMetrics |
| 654 |
require.NoError(t, testTel.Reader.Collect(ctx, &rm)) |
| 655 |
|
| 656 |
require.NotNil(t, rm) |
| 657 |
require.NotNil(t, rm.ScopeMetrics) |
| 658 |
|
| 659 |
assert.Len(t, rm.ScopeMetrics, len(expectedScopeMetrics)) |
| 660 |
|
| 661 |
for _, actualScopeMetrics := range rm.ScopeMetrics { |
| 662 |
expectedScopeMetrics, ok := expectedScopeMetrics[actualScopeMetrics.Scope.Attributes] |
| 663 |
require.True(t, ok) |
| 664 |
|
| 665 |
for _, actualMetric := range actualScopeMetrics.Metrics { |
| 666 |
expectedMetric, ok := expectedScopeMetrics[actualMetric.Name] |
| 667 |
require.True(t, ok) |
| 668 |
|
| 669 |
for _, actualPoint := range actualMetric.Data.(metricdata.Sum[int64]).DataPoints { |
| 670 |
expectedPoint, ok := expectedMetric[actualPoint.Attributes] |
| 671 |
require.True(t, ok) |
| 672 |
|
| 673 |
assert.Equal(t, int64(expectedPoint), actualPoint.Value) |
| 674 |
} |
| 675 |
} |
| 676 |
} |
| 677 |
|
| 678 |
assert.NoError(t, testTel.Shutdown(ctx)) |
| 679 |
} |
| 680 |
|
| 681 |
// map[dataPointAttrs]value |
| 682 |
type simpleMetric map[attribute.Set]int |
| 683 |
|
| 684 |
// map[metricName]simpleMetric |
| 685 |
type simpleMetricMap map[string]simpleMetric |
| 686 |
|
| 687 |
// map[scopeAttrs]simpleMetricMap |
| 688 |
type simpleScopeMetrics map[attribute.Set]simpleMetricMap |