Skip to content

Commit

Permalink
[extension/zpages] Add feature gate summary page
Browse files Browse the repository at this point in the history
Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>
  • Loading branch information
Aneurysm9 committed Feb 10, 2022
1 parent 94516e0 commit 47ab80b
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 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)

## v0.44.0 Beta

Expand Down
24 changes: 24 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,23 @@ 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 the summary table for one component type (receivers, processors, exporters).
// Id does not write the header or footer.
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
}

0 comments on commit 47ab80b

Please sign in to comment.