Skip to content

Commit

Permalink
[extension/zpages] Add feature gate summary page (#4834)
Browse files Browse the repository at this point in the history
* [extension/zpages] Add feature gate summary page

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* Add link to featurez on servicez, add featurez to README

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>
  • Loading branch information
Aneurysm9 authored Feb 14, 2022
1 parent 97ffae5 commit 1765388
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

- Reject invalid queue size exporterhelper (#4799)
- Transform configmapprovider.Retrieved interface to a struct (#4789)
- Added feature gate summary to zpages extension (#4834)

## 🚩 Deprecations 🚩

Expand Down
13 changes: 10 additions & 3 deletions extension/zpagesextension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ The collector exposes the following zPage routes:
### ServiceZ
ServiceZ gives an overview of the collector services by gives quick access to the
`pipelinez` and `extensionz` zPages. The page also provides build and runtime
information.
ServiceZ gives an overview of the collector services and quick access to the
`pipelinez`, `extensionz`, and `featurez` zPages. The page also provides build
and runtime information.

Example URL: http://localhost:55679/debug/servicez

Expand All @@ -48,6 +48,13 @@ ExtensionZ shows the extensions that are active in the collector.

Example URL: http://localhost:55679/debug/extensionz

### FeatureZ

FeatureZ lists the feature gates available along with their current status
and description.

Example URL: http://localhost:55679/debug/featurez

### TraceZ
The TraceZ route is available to examine and bucketize spans by latency buckets for
example
Expand Down
23 changes: 23 additions & 0 deletions service/internal/zpages/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ var (
//go:embed templates/properties_table.html
propertiesTableBytes []byte
propertiesTableTemplate = parseTemplate("properties_table", propertiesTableBytes)

//go:embed templates/features_table.html
featuresTableBytes []byte
featuresTableTemplate = parseTemplate("features_table", featuresTableBytes)
)

func parseTemplate(name string, bytes []byte) *template.Template {
Expand Down Expand Up @@ -156,3 +160,22 @@ func getKey(row [2]string) string {
func getValue(row [2]string) string {
return row[1]
}

// FeatureGateTableData contains data for feature gate table template.
type FeatureGateTableData struct {
Rows []FeatureGateTableRowData
}

// FeatureGateTableRowData contains data for one row in feature gate table template.
type FeatureGateTableRowData struct {
ID string
Enabled bool
Description string
}

// WriteHTMLFeaturesTable writes a table summarizing registered feature gates.
func WriteHTMLFeaturesTable(w io.Writer, ftd FeatureGateTableData) {
if err := featuresTableTemplate.Execute(w, ftd); err != nil {
log.Printf("zpages: executing template: %v", err)
}
}
19 changes: 19 additions & 0 deletions service/internal/zpages/templates/features_table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<table style="border-spacing: 0">
<tr>
<td colspan=1 style="text-align: left"><b>ID</b></td>
<td>&nbsp;&nbsp;|&nbsp;&nbsp;</td>
<td colspan=1 style="text-align: center"><b>Enabled</b></td>
<td>&nbsp;&nbsp;|&nbsp;&nbsp;</td>
<td colspan=1 style="text-align: center"><b>Description</b></td>
</tr>
{{range $rowindex, $row := .Rows}}
{{- if even $rowindex}}
<tr style="background: #eee">
{{else}}
<tr>{{end -}}
<td>{{$row.ID}}</td><td>&nbsp;&nbsp;|&nbsp;&nbsp;</td>
<td>{{$row.Enabled}}</td><td>&nbsp;&nbsp;|&nbsp;&nbsp;</td>
<td>{{$row.Description}}</td><td>&nbsp;&nbsp;|&nbsp;&nbsp;</td>
</tr>
{{end}}
</table>
9 changes: 9 additions & 0 deletions service/internal/zpages/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ func TestNoCrash(t *testing.T) {
assert.NotPanics(t, func() {
WriteHTMLPropertiesTable(buf, PropertiesTableData{Name: "Bar", Properties: [][2]string{{"key", "value"}}})
})
assert.NotPanics(t, func() {
WriteHTMLFeaturesTable(buf, FeatureGateTableData{Rows: []FeatureGateTableRowData{
{
ID: "test",
Enabled: false,
Description: "test gate",
},
}})
})
assert.NotPanics(t, func() { WriteHTMLPageFooter(buf) })
assert.NotPanics(t, func() { WriteHTMLPageFooter(buf) })
}
28 changes: 28 additions & 0 deletions service/zpages.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/internal/version"
"go.opentelemetry.io/collector/service/featuregate"
"go.opentelemetry.io/collector/service/internal/zpages"
)

Expand All @@ -31,6 +32,7 @@ const (
servicezPath = "servicez"
pipelinezPath = "pipelinez"
extensionzPath = "extensionz"
featurezPath = "featurez"

zPipelineName = "zpipelinename"
zComponentName = "zcomponentname"
Expand All @@ -42,6 +44,7 @@ func (srv *service) RegisterZPages(mux *http.ServeMux, pathPrefix string) {
mux.Handle(path.Join(pathPrefix, tracezPath), otelzpages.NewTracezHandler(srv.zPagesSpanProcessor))
mux.HandleFunc(path.Join(pathPrefix, servicezPath), srv.handleServicezRequest)
mux.HandleFunc(path.Join(pathPrefix, pipelinezPath), srv.handlePipelinezRequest)
mux.HandleFunc(path.Join(pathPrefix, featurezPath), handleFeaturezRequest)
mux.HandleFunc(path.Join(pathPrefix, extensionzPath), func(w http.ResponseWriter, r *http.Request) {
handleExtensionzRequest(srv, w, r)
})
Expand All @@ -60,6 +63,11 @@ func (srv *service) handleServicezRequest(w http.ResponseWriter, r *http.Request
ComponentEndpoint: extensionzPath,
Link: true,
})
zpages.WriteHTMLComponentHeader(w, zpages.ComponentHeaderData{
Name: "Features",
ComponentEndpoint: featurezPath,
Link: true,
})
zpages.WriteHTMLPropertiesTable(w, zpages.PropertiesTableData{Name: "Build And Runtime", Properties: version.RuntimeVar()})
zpages.WriteHTMLPageFooter(w)
}
Expand Down Expand Up @@ -151,3 +159,23 @@ func getExtensionsSummaryTableData(host component.Host) zpages.SummaryExtensions
})
return data
}

func handleFeaturezRequest(w http.ResponseWriter, r *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{}
for _, g := range featuregate.List() {
data.Rows = append(data.Rows, zpages.FeatureGateTableRowData{
ID: g.ID,
Enabled: g.Enabled,
Description: g.Description,
})
}

return data
}

0 comments on commit 1765388

Please sign in to comment.