Debian Codegraph @

docs/internal-architecture.md

raw
1 ## Internal architecture
2
3 This document describes the Collector internal architecture and startup flow. It can be helpful if you are starting to contribute to the Collector codebase.
4
5 For the end-user focused architecture document, please see the [opentelemetry.io's Architecture documentation](https://opentelemetry.io/docs/collector/architecture/). While it is end user focused, it's still a good place to start if you're trying to learn about the Collector codebase.
6
7 ### Startup Diagram
8 ```mermaid
9 flowchart TD
10 A("`**command.NewCommand**`") -->|1| B("`**updateSettingsUsingFlags**`")
11 A --> |2| C("`**NewCollector**
12 Creates and returns a new instance of Collector`")
13 A --> |3| D("`**Collector.Run**
14 Starts the collector and blocks until it shuts down`")
15 D --> E("`**setupConfigurationComponents**`")
16 E --> |1| F("`**getConfMap**`")
17 E ---> |2| G("`**Service.New**
18 Initializes telemetry, then initializes the pipelines`")
19 E --> |3| Q("`**Service.Start**
20 1. Start all extensions.
21 2. Notify extensions about Collector configuration
22 3. Start all pipelines.
23 4. Notify extensions that the pipeline is ready.
24 `")
25 Q --> R("`**Graph.StartAll**
26 Calls Start on each component in reverse topological order`")
27 G --> H("`**initExtensionsAndPipeline**
28 Creates extensions and then builds the pipeline graph`")
29 H --> I("`**Graph.Build**
30 Converts the settings to an internal graph representation`")
31 I --> |1| J("`**createNodes**
32 Builds the node objects from pipeline configuration and adds to graph. Also validates connectors`")
33 I --> |2| K("`**createEdges**
34 Iterates through the pipelines and creates edges between components`")
35 I --> |3| L("`**buildComponents**
36 Topological sort the graph, and create each component in reverse order`")
37 L --> M(Receiver Factory) & N(Processor Factory) & O(Exporter Factory) & P(Connector Factory)
38 ```
39 ### Where to start to read the code
40 Here is a brief list of useful and/or important files and interfaces that you may find valuable to glance through.
41 Most of these have package-level documentation and function/struct-level comments that help explain the Collector!
42
43 - [collector.go](../otelcol/collector.go)
44 - [graph.go](../service/internal/graph/graph.go)
45 - [component.go](../component/component.go)
46
47 #### Factories
48 Each component type contains a `Factory` interface along with its corresponding `NewFactory` function.
49 Implementations of new components use this `NewFactory` function in their implementation to register key functions with
50 the Collector. An example of this is in [receiver.go](../receiver/receiver.go).
51
52 For example, the Collector uses this interface to give receivers a handle to a `nextConsumer` -
53 which represents where the receiver will send its data next in its telemetry pipeline.