-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change adds a test webserver that helps validate: * external access works as expected * metrics can be collected It may be extended in the future to allow for testing gRPC, etc. Jira: INFRA-5878
- Loading branch information
1 parent
e58ae16
commit f79ad6e
Showing
3 changed files
with
89 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") | ||
load("@io_bazel_rules_docker//container:container.bzl", "container_image", "container_push") | ||
load("@rules_pkg//:pkg.bzl", "pkg_tar") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["main.go"], | ||
importpath = "github.com/enfabrica/enkit/infra/k8s_dummy", | ||
visibility = ["//visibility:private"], | ||
deps = [ | ||
"//lib/server:go_default_library", | ||
"@com_github_prometheus_client_golang//prometheus:go_default_library", | ||
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library", | ||
"@com_github_prometheus_client_golang//prometheus/promhttp:go_default_library", | ||
], | ||
) | ||
|
||
go_binary( | ||
name = "k8s_dummy", | ||
embed = [":go_default_library"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
pkg_tar( | ||
name = "k8s_dummy_tar", | ||
srcs = [":k8s_dummy"], | ||
package_dir = "/enfabrica/bin", | ||
) | ||
|
||
container_image( | ||
name = "k8s_dummy_image", | ||
base = "@golang_base//image", | ||
cmd = [ | ||
"/enfabrica/bin/k8s_dummy", | ||
], | ||
tars = [ | ||
":k8s_dummy_tar", | ||
], | ||
) | ||
|
||
container_push( | ||
name = "k8s_dummy_image_push", | ||
format = "Docker", | ||
image = ":k8s_dummy_image", | ||
registry = "gcr.io", | ||
repository = "devops-284019/infra/k8s_dummy", | ||
# TODO: Change this tag to "live" | ||
tag = "testing", | ||
) |
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,40 @@ | ||
// Webserver that exposes metrics for testing k8s setups | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/enfabrica/enkit/lib/server" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
) | ||
|
||
var ( | ||
metricPathVisits = promauto.NewCounterVec(prometheus.CounterOpts{ | ||
Subsystem: "k8s_dummy", | ||
Name: "path_visit_count", | ||
}, | ||
[]string{ | ||
"path", | ||
}, | ||
) | ||
) | ||
|
||
func printPath(w http.ResponseWriter, r *http.Request) { | ||
metricPathVisits.WithLabelValues(r.URL.Path).Inc() | ||
w.WriteHeader(200) | ||
fmt.Fprintf(w, "You reached page: %s\n", r.URL.Path) | ||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
mux := http.NewServeMux() | ||
mux.Handle("/metrics", promhttp.Handler()) | ||
mux.HandleFunc("/printpath/", printPath) | ||
|
||
server.Run(mux, nil, nil) | ||
} |