Skip to content

Commit

Permalink
[golang] Use HTTP interface for parametric tests #2799
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeauchesne committed Sep 2, 2024
1 parent 15713a6 commit d7106de
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
3 changes: 2 additions & 1 deletion utils/_context/_scenarios/parametric.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def configure(self, config):
self._clean_networks()

# https://github.com/DataDog/system-tests/issues/2799
if library in ("nodejs", "python"):
if library in ("nodejs", "python", "golang"):
output = _get_client().containers.run(
self.apm_test_server_definition.container_tag,
remove=True,
Expand Down Expand Up @@ -423,6 +423,7 @@ def golang_library_factory():
COPY {golang_reldir}/. /app
# download the proper tracer version
COPY utils/build/docker/golang/install_ddtrace.sh binaries* /binaries/
COPY utils/build/docker/golang/parametric/system_tests_library_version.sh system_tests_library_version.sh
RUN /binaries/install_ddtrace.sh
RUN go install
Expand Down
7 changes: 4 additions & 3 deletions utils/_context/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ def configure(self, replay):
)

# https://github.com/DataDog/system-tests/issues/2799
if self.library in ("nodejs", "python"):
if self.library in ("nodejs", "python", "golang"):
self.healthcheck = {
"test": f"curl --fail --silent --show-error localhost:{self.port}/healthcheck",
"retries": 60,
Expand Down Expand Up @@ -702,13 +702,14 @@ def post_start(self):

# new way of getting info from the weblog. Only working for nodejs and python right now
# https://github.com/DataDog/system-tests/issues/2799
if self.library in ("nodejs", "python"):
if self.library in ("nodejs", "python", "golang"):
with open(self.healthcheck_log_file, mode="r", encoding="utf-8") as f:
data = json.load(f)
lib = data["library"]

self._library = LibraryVersion(lib["language"], lib["version"])
self.libddwaf_version = LibraryVersion("libddwaf", lib["libddwaf_version"]).version
if "libddwaf_version" in lib:
self.libddwaf_version = LibraryVersion("libddwaf", lib["libddwaf_version"]).version

if self.appsec_rules_version == "0.0.0" and "appsec_event_rules_version" in lib:
self.appsec_rules_version = LibraryVersion("appsec_rules", lib["appsec_event_rules_version"]).version
Expand Down
34 changes: 34 additions & 0 deletions utils/build/docker/golang/app/net-http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,40 @@ func main() {
w.WriteHeader(http.StatusOK)
})

mux.HandleFunc("/healthcheck", func(w http.ResponseWriter, r *http.Request) {
tracerVersion, err := os.ReadFile("SYSTEM_TESTS_LIBRARY_VERSION")
if err != nil {
http.Error(w, "Can't get SYSTEM_TESTS_LIBRARY_VERSION", http.StatusInternalServerError)
return
}

appsec_rules_version, err := os.ReadFile("SYSTEM_TESTS_APPSEC_EVENT_RULES_VERSION")
if err != nil {
http.Error(w, "Can't get SYSTEM_TESTS_APPSEC_EVENT_RULES_VERSION", http.StatusInternalServerError)
return
}

libray := map[string]interface{}{
"language": "golang",
"version": string(tracerVersion),
"appsec_event_rules_version": string(appsec_rules_version),
}

data := map[string]interface{}{
"status": "ok",
"library": libray,
}

jsonData, err := json.Marshal(data)
if err != nil {
http.Error(w, "Can;t build JSON data", http.StatusInternalServerError)
return
}

w.Header().Set("Content-Type", "application/json")
w.Write(jsonData)
})

mux.HandleFunc("/waf", func(w http.ResponseWriter, r *http.Request) {
body, err := common.ParseBody(r)
if err == nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

cat SYSTEM_TESTS_LIBRARY_VERSION

0 comments on commit d7106de

Please sign in to comment.