Skip to content

Commit

Permalink
[golang] Use /healthcheck to get library version #2799
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeauchesne authored and mtoffl01 committed Sep 11, 2024
1 parent 25899e7 commit 81e8ae7
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 @@ -149,7 +149,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 @@ -422,6 +422,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 @@ -681,7 +681,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 --max-time 2 localhost:{self.port}/healthcheck",
"retries": 60,
Expand Down Expand Up @@ -715,13 +715,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 81e8ae7

Please sign in to comment.