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

Remove sample target in favour or self-profiling #4

Merged
merged 1 commit into from
Oct 31, 2024
Merged
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
23 changes: 0 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,6 @@ described in the table below:
| `--event-reader-url` | `AUTOPGO_EVENT_READER_URL` | None | Specifies the event bus to use for consuming profile events. See the documentation on [URLs](#url-configuration) for more details |
| `--blob-store-url` | `AUTOPGO_BLOB_STORE_URL` | None | Specifies the blob storage provider to use for reading & writing profiles. See the documentation on [URLs](#url-configuration) for more details |

### Target

The target command is used to spin up a basic HTTP application that exposes pprof endpoints. This is to be used as a
test target for the [scraper](#scraper).

#### Command

To run the sample target, use the following command:

```shell
autopgo target
```

#### Configuration

The `target` command also accepts some command-line flags that may also be set via environment variables. They are
described in the table below:

| Flag | Environment Variable | Default | Description |
|:-------------------:|:--------------------:|:-------:|:-----------------------------------------------------------------------------------------|
| `--log-level`, `-l` | `AUTOPGO_LOG_LEVEL` | `info` | Controls the verbosity of log output, valid values are `debug`, `info`, `warn` & `error` |
| `--port`, `-p` | `AUTOPGO_PORT` | `8081` | Specifies the port to use for HTTP traffic |

## Events

The [server](#server) and [worker](#worker) components communicate via events published to and read from an event bus.
Expand Down
42 changes: 0 additions & 42 deletions cmd/target/target.go

This file was deleted.

4 changes: 2 additions & 2 deletions example.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"scrapeFrequency": 30,
"targets": [
{
"app": "test",
"address": "http://localhost:8081/debug/pprof/profile"
"app": "autopgo",
"address": "http://localhost:8080/debug/pprof/profile"
}
]
}
18 changes: 18 additions & 0 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"net/http"
"net/http/pprof"
"time"

"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -41,6 +42,8 @@ func Run(ctx context.Context, config Config) error {
controller.Register(mux)
}

registerDebug(mux)

server := &http.Server{
Handler: mux,
Addr: fmt.Sprintf(":%d", config.Port),
Expand All @@ -64,3 +67,18 @@ func Run(ctx context.Context, config Config) error {

return group.Wait()
}

func registerDebug(mux *http.ServeMux) {
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)

mux.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
mux.Handle("/debug/pprof/heap", pprof.Handler("heap"))
mux.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
mux.Handle("/debug/pprof/block", pprof.Handler("block"))
mux.Handle("/debug/pprof/allocs", pprof.Handler("allocs"))
mux.Handle("/debug/pprof/mutex", pprof.Handler("mutex"))
}
29 changes: 0 additions & 29 deletions internal/target/server.go

This file was deleted.

2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/davidsbond/autopgo/cmd/list"
"github.com/davidsbond/autopgo/cmd/scrape"
"github.com/davidsbond/autopgo/cmd/server"
"github.com/davidsbond/autopgo/cmd/target"
"github.com/davidsbond/autopgo/cmd/upload"
"github.com/davidsbond/autopgo/cmd/worker"
"github.com/davidsbond/autopgo/internal/logger"
Expand Down Expand Up @@ -83,7 +82,6 @@ func main() {
download.Command(),
server.Command(),
scrape.Command(),
target.Command(),
list.Command(),
delete.Command(),
)
Expand Down