forked from open-telemetry/opentelemetry-collector
/
zpages.go
83 lines (74 loc) · 2.89 KB
/
zpages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package service // import "go.opentelemetry.io/collector/service"
import (
"net/http"
"path"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/service/internal/runtimeinfo"
"go.opentelemetry.io/collector/service/internal/zpages"
)
const (
// Paths
zServicePath = "servicez"
zPipelinePath = "pipelinez"
zExtensionPath = "extensionz"
zFeaturePath = "featurez"
)
func (host *serviceHost) 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 *serviceHost) 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: runtimeinfo.Info()})
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},
}
}