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

Hack: enable full dead code elimination in binaries #32527

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions cmd/process-agent/subcommands/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ func writeNotRunning(log log.Component, w io.Writer) {
}

func writeError(log log.Component, w io.Writer, e error) {
tpl, err := template.New("").Funcs(compStatus.TextFmap()).Parse(errorMessage)
_, err := template.New("").Funcs(compStatus.TextFmap()).Parse(errorMessage)
if err != nil {
_ = log.Error(err)
}

err = tpl.Execute(w, e)
if err != nil {
_ = log.Error(err)
}
// err = tpl.Execute(w, e)
// if err != nil {
// _ = log.Error(err)
// }
}

func fetchStatus(statusURL string) ([]byte, error) {
Expand Down
13 changes: 7 additions & 6 deletions comp/core/gui/guiimpl/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,23 +213,24 @@ func renderIndexPage(w http.ResponseWriter, _ *http.Request) {
return
}

t, e = t.Parse(instructionTemplate)
_, e = t.Parse(instructionTemplate)
if e != nil {
http.Error(w, e.Error(), http.StatusInternalServerError)
return
}

e = t.Execute(w, struct {
_ = struct {
RestartEnabled bool
DocURL template.URL
}{
RestartEnabled: restartEnabled(),
DocURL: docURL,
})
if e != nil {
http.Error(w, e.Error(), http.StatusInternalServerError)
return
}
// e = t.Execute(w, )
// if e != nil {
// http.Error(w, e.Error(), http.StatusInternalServerError)
// return
// }
}

func serveAssets(w http.ResponseWriter, req *http.Request) {
Expand Down
8 changes: 4 additions & 4 deletions comp/core/gui/guiimpl/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ func renderError(name string) (string, error) {
return b.String(), nil
}

func fillTemplate(w io.Writer, data Data, request string) error {
func fillTemplate(_ io.Writer, _ Data, request string) error {
t := template.New(request + ".tmpl")
t.Funcs(fmap)
tmpl, err := templatesFS.ReadFile("views/templates/" + request + ".tmpl")
if err != nil {
return err
}
t, e := t.Parse(string(tmpl))
_, e := t.Parse(string(tmpl))
if e != nil {
return e
}
e = t.Execute(w, data)
return e
// e = t.Execute(w, data)
return nil
}
19 changes: 10 additions & 9 deletions comp/core/secrets/secretsimpl/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,14 @@ func (r *secretResolver) Refresh() (string, error) {

// render a report
t := template.New("secret_refresh")
t, err = t.Parse(secretRefreshTmpl)
_, err = t.Parse(secretRefreshTmpl)
if err != nil {
return "", err
}
b := new(strings.Builder)
if err = t.Execute(b, refreshResult); err != nil {
return "", err
}
// if err = t.Execute(b, refreshResult); err != nil {
// return "", err
// }
return b.String(), auditRecordErr
}

Expand Down Expand Up @@ -592,7 +592,7 @@ func (r *secretResolver) GetDebugInfo(w io.Writer) {
return
}

t, err = t.Parse(permissionsDetailsTemplate)
_, err = t.Parse(permissionsDetailsTemplate)
if err != nil {
fmt.Fprintf(w, "error parsing secret permissions details template: %s", err)
return
Expand Down Expand Up @@ -632,8 +632,9 @@ func (r *secretResolver) GetDebugInfo(w io.Writer) {
info.Handles[handle] = details
}

err = t.Execute(w, info)
if err != nil {
fmt.Fprintf(w, "error rendering secret info: %s", err)
}
_ = info
// err = t.Execute(w, info)
// if err != nil {
// fmt.Fprintf(w, "error rendering secret info: %s", err)
// }
}
12 changes: 6 additions & 6 deletions comp/core/status/render_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,23 @@ func TextFmap() ttemplate.FuncMap {
const timeFormat = "2006-01-02 15:04:05.999 MST"

// RenderHTML reads, parse and execute template from embed.FS
func RenderHTML(templateFS embed.FS, template string, buffer io.Writer, data any) error {
func RenderHTML(templateFS embed.FS, template string, _ io.Writer, _ any) error {
tmpl, tmplErr := templateFS.ReadFile(path.Join("status_templates", template))
if tmplErr != nil {
return tmplErr
}
t := htemplate.Must(htemplate.New(template).Funcs(HTMLFmap()).Parse(string(tmpl)))
return t.Execute(buffer, data)
_ = htemplate.Must(htemplate.New(template).Funcs(HTMLFmap()).Parse(string(tmpl)))
return nil //t.Execute(buffer, data)
}

// RenderText reads, parse and execute template from embed.FS
func RenderText(templateFS embed.FS, template string, buffer io.Writer, data any) error {
func RenderText(templateFS embed.FS, template string, _ io.Writer, _ any) error {
tmpl, tmplErr := templateFS.ReadFile(path.Join("status_templates", template))
if tmplErr != nil {
return tmplErr
}
t := ttemplate.Must(ttemplate.New(template).Funcs(TextFmap()).Parse(string(tmpl)))
return t.Execute(buffer, data)
_ = ttemplate.Must(ttemplate.New(template).Funcs(TextFmap()).Parse(string(tmpl)))
return nil //t.Execute(buffer, data)
}

func doNotEscape(value string) htemplate.HTML {
Expand Down
12 changes: 6 additions & 6 deletions comp/core/status/statusimpl/common_header_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@ func (h *headerProvider) JSON(_ bool, stats map[string]interface{}) error {
return nil
}

func (h *headerProvider) Text(_ bool, buffer io.Writer) error {
func (h *headerProvider) Text(_ bool, _ io.Writer) error {
tmpl, tmplErr := templatesFS.ReadFile(path.Join("templates", "text.tmpl"))
if tmplErr != nil {
return tmplErr
}
t := textTemplate.Must(textTemplate.New("header").Funcs(h.textTemplatesFunctions).Parse(string(tmpl)))
return t.Execute(buffer, h.data())
_ = textTemplate.Must(textTemplate.New("header").Funcs(h.textTemplatesFunctions).Parse(string(tmpl)))
return nil //t.Execute(buffer, h.data())
}

func (h *headerProvider) HTML(_ bool, buffer io.Writer) error {
func (h *headerProvider) HTML(_ bool, _ io.Writer) error {
tmpl, tmplErr := templatesFS.ReadFile(path.Join("templates", "html.tmpl"))
if tmplErr != nil {
return tmplErr
}
t := htmlTemplate.Must(htmlTemplate.New("header").Funcs(h.htmlTemplatesFunctions).Parse(string(tmpl)))
return t.Execute(buffer, h.data())
_ = htmlTemplate.Must(htmlTemplate.New("header").Funcs(h.htmlTemplatesFunctions).Parse(string(tmpl)))
return nil //t.Execute(buffer, h.data())
}

func (h *headerProvider) data() map[string]interface{} {
Expand Down
6 changes: 3 additions & 3 deletions comp/core/status/statusimpl/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,11 @@ func newLine(buffer *bytes.Buffer) {
buffer.Write([]byte("\n"))
}

func renderErrors(w io.Writer, errs []error) error {
func renderErrors(_ io.Writer, _ []error) error {
tmpl, tmplErr := templatesFS.ReadFile(path.Join("templates", "errors.tmpl"))
if tmplErr != nil {
return tmplErr
}
t := template.Must(template.New("errors").Parse(string(tmpl)))
return t.Execute(w, errs)
_ = template.Must(template.New("errors").Parse(string(tmpl)))
return nil //t.Execute(w, errs)
}
19 changes: 19 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@ retract (
// See https://github.com/DataDog/datadog-agent/blob/main/docs/dev/gomodreplace.md
// for more details.

replace (
// prevent using reflect.Type.MethodByName with non-constant argument
github.com/Intevation/gval => github.com/pgimalac/gval v1.3.1-0.20241226144305-104364cd0aa3
// comment out a use of text/template
github.com/cheggaaa/pb/v3 => github.com/pgimalac/pb/v3 v3.1.6-0.20241226144746-8962a0214971
// avoid using reflect.Type.Method with non-constant argument
github.com/google/go-cmp => github.com/pgimalac/go-cmp v0.6.1-0.20241226143757-a715dfd9338b
// reflect2 has a type which wraps reflect.Type, which makes the linker consider that Method and MethodByName are reachable. This fix shadows both methods to make them explicitly unreachable.
github.com/modern-go/reflect2 => github.com/pgimalac/reflect2 v0.0.0-20241226135511-3c6e286be18b
// comment out uses of text/template
github.com/open-policy-agent/opa => github.com/pgimalac/opa v0.0.0-20241226172958-398772fbb5c0
// https://github.com/spf13/cobra/pull/1956
github.com/spf13/cobra => github.com/aarzilli/cobra v1.1.3-0.20241206153912-45cac892e43f
// comment out a use of text/template
github.com/xeipuuv/gojsonschema => github.com/pgimalac/gojsonschema v1.2.1-0.20241226211709-d63a0dde5719
// comment out a use of text/template
go.uber.org/dig => github.com/pgimalac/dig v1.18.1-0.20241226143044-f328231d7d7e
)

// Internal deps fix version
replace (
github.com/cihub/seelog => github.com/cihub/seelog v0.0.0-20151216151435-d2c6e5aa9fbf // v2.6
Expand Down
47 changes: 16 additions & 31 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions pkg/dynamicinstrumentation/ebpf/ebpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ func CompileBPFProgram(procInfo *ditypes.ProcessInfo, probe *ditypes.Probe) erro
if err != nil {
return err
}
programTemplate, err := template.New("program_template").Parse(string(fileContents))
if err != nil {
return err
}
err = programTemplate.Execute(out, probe)
_, err = template.New("program_template").Parse(string(fileContents))
if err != nil {
return err
}
// err = programTemplate.Execute(out, probe)
// if err != nil {
// return err
// }
return nil
}

Expand Down
Loading
Loading