Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[extension/zpages] Add feature gate summary page #4834

Merged
merged 3 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

## v0.44.0 Beta

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) })
}
23 changes: 23 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 Down Expand Up @@ -151,3 +154,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
}