-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add webhost with metrics endpoint to benchmark tool
- Loading branch information
1 parent
cee012f
commit 35a031d
Showing
6 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
benchmark: | ||
duration: 15m | ||
network: mainnet | ||
server: | ||
port: 8080 | ||
|
||
consensus: | ||
address: | ||
metrics: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package host | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log/slog" | ||
"net/http" | ||
) | ||
|
||
const hostName = "0.0.0.0" | ||
|
||
type WebHost struct { | ||
server http.Server | ||
} | ||
|
||
func New(port uint16, handler http.Handler) *WebHost { | ||
return &WebHost{ | ||
server: http.Server{ | ||
Addr: fmt.Sprintf("%s:%d", hostName, port), | ||
Handler: handler, | ||
}, | ||
} | ||
} | ||
|
||
func (h *WebHost) Run() { | ||
go func() { | ||
if err := h.server.ListenAndServe(); err != nil && err != http.ErrServerClosed { | ||
const errMsg = "error running web host" | ||
slog.With("error", err.Error()).Error(errMsg) | ||
panic(errMsg) | ||
} | ||
}() | ||
} | ||
|
||
func (h *WebHost) Terminate(ctx context.Context) error { | ||
return h.server.Shutdown(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package route | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
) | ||
|
||
type Router struct { | ||
router *http.ServeMux | ||
} | ||
|
||
func NewRouter() *Router { | ||
router := http.NewServeMux() | ||
return &Router{ | ||
router: router, | ||
} | ||
} | ||
|
||
func (r *Router) WithMetrics() *Router { | ||
r.router.Handle("/metrics", promhttp.Handler()) | ||
return r | ||
} | ||
|
||
func (r *Router) Router() *http.ServeMux { | ||
return r.router | ||
} |