-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#### Description This is a prep PR to reduce the size of #10777. As part of the work to make our `component.Host` implementation implement `componentstatus.Reporter` (see #10852), the `host` struct and `graph` logic need to be closer together. This is because, as part of #10777 `StartAll` is changed to depend on our specific `Host` type instead of a `component.Host`. Our host already has a dependency on `graph`, so it can't be moved into its own module. <!-- Issue number if applicable --> #### Link to tracking issue Related to #10777 Related to #10413
- Loading branch information
1 parent
b0085e5
commit d5d1f82
Showing
5 changed files
with
187 additions
and
195 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package graph // import "go.opentelemetry.io/collector/service/internal/graph" | ||
|
||
import ( | ||
"net/http" | ||
"path" | ||
"runtime" | ||
"time" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/connector" | ||
"go.opentelemetry.io/collector/exporter" | ||
"go.opentelemetry.io/collector/extension" | ||
"go.opentelemetry.io/collector/featuregate" | ||
"go.opentelemetry.io/collector/processor" | ||
"go.opentelemetry.io/collector/receiver" | ||
"go.opentelemetry.io/collector/service/extensions" | ||
"go.opentelemetry.io/collector/service/internal/zpages" | ||
) | ||
|
||
// TODO: remove as part of https://github.com/open-telemetry/opentelemetry-collector/issues/7370 for service 1.0 | ||
type getExporters interface { | ||
GetExporters() map[component.DataType]map[component.ID]component.Component | ||
} | ||
|
||
var _ getExporters = (*Host)(nil) | ||
var _ component.Host = (*Host)(nil) | ||
|
||
type Host struct { | ||
AsyncErrorChannel chan error | ||
Receivers *receiver.Builder | ||
Processors *processor.Builder | ||
Exporters *exporter.Builder | ||
Connectors *connector.Builder | ||
Extensions *extension.Builder | ||
|
||
BuildInfo component.BuildInfo | ||
|
||
Pipelines *Graph | ||
ServiceExtensions *extensions.Extensions | ||
} | ||
|
||
func (host *Host) GetFactory(kind component.Kind, componentType component.Type) component.Factory { | ||
switch kind { | ||
case component.KindReceiver: | ||
return host.Receivers.Factory(componentType) | ||
case component.KindProcessor: | ||
return host.Processors.Factory(componentType) | ||
case component.KindExporter: | ||
return host.Exporters.Factory(componentType) | ||
case component.KindConnector: | ||
return host.Connectors.Factory(componentType) | ||
case component.KindExtension: | ||
return host.Extensions.Factory(componentType) | ||
} | ||
return nil | ||
} | ||
|
||
func (host *Host) GetExtensions() map[component.ID]component.Component { | ||
return host.ServiceExtensions.GetExtensions() | ||
} | ||
|
||
// Deprecated: [0.79.0] This function will be removed in the future. | ||
// Several components in the contrib repository use this function so it cannot be removed | ||
// before those cases are removed. In most cases, use of this function can be replaced by a | ||
// connector. See https://github.com/open-telemetry/opentelemetry-collector/issues/7370 and | ||
// https://github.com/open-telemetry/opentelemetry-collector/pull/7390#issuecomment-1483710184 | ||
// for additional information. | ||
func (host *Host) GetExporters() map[component.DataType]map[component.ID]component.Component { | ||
return host.Pipelines.GetExporters() | ||
} | ||
|
||
func (host *Host) NotifyComponentStatusChange(source *component.InstanceID, event *component.StatusEvent) { | ||
host.ServiceExtensions.NotifyComponentStatusChange(source, event) | ||
if event.Status() == component.StatusFatalError { | ||
host.AsyncErrorChannel <- event.Err() | ||
} | ||
} | ||
|
||
const ( | ||
// Paths | ||
zServicePath = "servicez" | ||
zPipelinePath = "pipelinez" | ||
zExtensionPath = "extensionz" | ||
zFeaturePath = "featurez" | ||
) | ||
|
||
var ( | ||
// InfoVar is a singleton instance of the Info struct. | ||
runtimeInfoVar [][2]string | ||
) | ||
|
||
func init() { | ||
runtimeInfoVar = [][2]string{ | ||
{"StartTimestamp", time.Now().String()}, | ||
{"Go", runtime.Version()}, | ||
{"OS", runtime.GOOS}, | ||
{"Arch", runtime.GOARCH}, | ||
// Add other valuable runtime information here. | ||
} | ||
} | ||
|
||
func (host *Host) RegisterZPages(mux *http.ServeMux, pathPrefix string) { | ||
mux.HandleFunc(path.Join(pathPrefix, zServicePath), host.zPagesRequest) | ||
mux.HandleFunc(path.Join(pathPrefix, zPipelinePath), host.Pipelines.HandleZPages) | ||
mux.HandleFunc(path.Join(pathPrefix, zExtensionPath), host.ServiceExtensions.HandleZPages) | ||
mux.HandleFunc(path.Join(pathPrefix, zFeaturePath), handleFeaturezRequest) | ||
} | ||
|
||
func (host *Host) zPagesRequest(w http.ResponseWriter, _ *http.Request) { | ||
w.Header().Set("Content-Type", "text/html; charset=utf-8") | ||
zpages.WriteHTMLPageHeader(w, zpages.HeaderData{Title: "Service " + host.BuildInfo.Command}) | ||
zpages.WriteHTMLPropertiesTable(w, zpages.PropertiesTableData{Name: "Build Info", Properties: getBuildInfoProperties(host.BuildInfo)}) | ||
zpages.WriteHTMLPropertiesTable(w, zpages.PropertiesTableData{Name: "Runtime Info", Properties: runtimeInfoVar}) | ||
zpages.WriteHTMLComponentHeader(w, zpages.ComponentHeaderData{ | ||
Name: "Pipelines", | ||
ComponentEndpoint: zPipelinePath, | ||
Link: true, | ||
}) | ||
zpages.WriteHTMLComponentHeader(w, zpages.ComponentHeaderData{ | ||
Name: "Extensions", | ||
ComponentEndpoint: zExtensionPath, | ||
Link: true, | ||
}) | ||
zpages.WriteHTMLComponentHeader(w, zpages.ComponentHeaderData{ | ||
Name: "Features", | ||
ComponentEndpoint: zFeaturePath, | ||
Link: true, | ||
}) | ||
zpages.WriteHTMLPageFooter(w) | ||
} | ||
|
||
func handleFeaturezRequest(w http.ResponseWriter, _ *http.Request) { | ||
w.Header().Set("Content-Type", "text/html; charset=utf-8") | ||
zpages.WriteHTMLPageHeader(w, zpages.HeaderData{Title: "Feature Gates"}) | ||
zpages.WriteHTMLFeaturesTable(w, getFeaturesTableData()) | ||
zpages.WriteHTMLPageFooter(w) | ||
} | ||
|
||
func getFeaturesTableData() zpages.FeatureGateTableData { | ||
data := zpages.FeatureGateTableData{} | ||
featuregate.GlobalRegistry().VisitAll(func(gate *featuregate.Gate) { | ||
data.Rows = append(data.Rows, zpages.FeatureGateTableRowData{ | ||
ID: gate.ID(), | ||
Enabled: gate.IsEnabled(), | ||
Description: gate.Description(), | ||
Stage: gate.Stage().String(), | ||
FromVersion: gate.FromVersion(), | ||
ToVersion: gate.ToVersion(), | ||
ReferenceURL: gate.ReferenceURL(), | ||
}) | ||
}) | ||
return data | ||
} | ||
|
||
func getBuildInfoProperties(buildInfo component.BuildInfo) [][2]string { | ||
return [][2]string{ | ||
{"Command", buildInfo.Command}, | ||
{"Description", buildInfo.Description}, | ||
{"Version", buildInfo.Version}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.