Author: Andy Green Date: Thu Jul 31 05:24:30 2025 +0100 server: record builder IP and pass to browser Co-developed-by: Gemini 2.5 Pro diff --git a/assets/sai.js b/assets/sai.js index 78a00d6..fd02ec6 100644 --- a/assets/sai.js +++ b/assets/sai.js @@ -878,9 +878,11 @@ function render_builders(jso) host !== jso.builders[n - 1].name.split('.')[0] || e.platform != samplat) { s += "
" + - sai_plat_icon(e.platform, 1); + sai_plat_icon(e.platform, 1) + + (e.peer_ip ? "
" + san(e.peer_ip) : ""); samplat = e.platform; did = 1; diff --git a/src/common/include/private.h b/src/common/include/private.h index f020053..5378226 100644 --- a/src/common/include/private.h +++ b/src/common/include/private.h @@ -344,6 +344,8 @@ typedef struct sai_plat { lws_dll2_owner_t servers; /* list of sai_plat_server_ref_t */ lws_dll2_owner_t chunk_cache; + char peer_ip[48]; + const char *name; const char *platform; diff --git a/src/common/struct-metadata.c b/src/common/struct-metadata.c index b96f3c4..cff297d 100644 --- a/src/common/struct-metadata.c +++ b/src/common/struct-metadata.c @@ -26,6 +26,7 @@ static const lws_struct_map_t lsm_plat[] = { LSM_UNSIGNED (sai_plat_t, ongoing, "ongoing"), LSM_UNSIGNED (sai_plat_t, instances, "instances"), LSM_STRING_PTR (sai_plat_t, platform, "platform"), + LSM_CARRAY (sai_plat_t, peer_ip, "peer_ip"), }; const lws_struct_map_t lsm_schema_map_plat_simple[] = { diff --git a/src/server/s-comms.c b/src/server/s-comms.c index db1d7b6..d071c44 100644 --- a/src/server/s-comms.c +++ b/src/server/s-comms.c @@ -705,6 +705,9 @@ callback_ws(struct lws *wsi, enum lws_callback_reasons reason, void *user, if (!strcmp((char *)start, "/builder")) { lwsl_info("%s: ESTABLISHED: builder\n", __func__); pss->wsi = wsi; + + lws_get_peer_simple(wsi, pss->peer_ip, sizeof(pss->peer_ip)); + /* * this adds our pss part, but not the logical builder * yet, until we get the ws rx diff --git a/src/server/s-private.h b/src/server/s-private.h index 39ec734..9db8a61 100644 --- a/src/server/s-private.h +++ b/src/server/s-private.h @@ -125,6 +125,8 @@ struct pss { sai_task_t alloc_task; struct lwsac *ac_alloc_task; + char peer_ip[48]; + int task_index; int log_cache_index; int log_cache_size; diff --git a/src/server/s-task.c b/src/server/s-task.c index e0a6f58..9c90bfd 100644 --- a/src/server/s-task.c +++ b/src/server/s-task.c @@ -322,13 +322,28 @@ sais_task_pending(struct vhd *vhd, struct pss *pss, const char *platform) lws_sql_purify(esc_plat, platform, sizeof(esc_plat)); assert(platform); - lws_snprintf(pf, sizeof(pf)," and (state != 3 and state != 4 and state != 5 and state != 6) and (created < %llu)", + /* + * this is looking at the state of *events* + * + * SAIES_WAITING = 0, + * SAIES_PASSED_TO_BUILDER = 1, + * SAIES_BEING_BUILT = 2, + * SAIES_SUCCESS = 3, + * SAIES_FAIL = 4, + * SAIES_CANCELLED = 5, + * SAIES_BEING_BUILT_HAS_FAILURES = 6, + * SAIES_DELETED = 7, + */ + lws_snprintf(pf, sizeof(pf)," and (state != 3 and state != 5) and (created < %llu)", (unsigned long long)(lws_now_secs() - 10)); n = lws_struct_sq3_deserialize(vhd->server.pdb, pf, "created desc ", lsm_schema_sq3_map_event, &o, &ac, 0, 10); - if (n < 0 || !o.head) + if (n < 0 || !o.count) { + lwsl_notice("%s: platform %s: bail1: n %d count %d\n", __func__, platform, n, o.count); + goto bail; + } // lwsl_notice("%s: plat %s, toplevel results %d\n", __func__, platform, o.count); @@ -340,20 +355,21 @@ sais_task_pending(struct vhd *vhd, struct pss *pss, const char *platform) char prev_event_uuid[33] = "", checked_uuid[33] = ""; char esc_repo[96], esc_ref[96]; uint64_t last_created; + int m; // lwsl_notice("candidate event %s '%s'\n", e->uuid, esc_plat); if (!sais_event_db_ensure_open(vhd, e->uuid, 0, &pdb)) { lws_snprintf(query, sizeof(query), "select count(state) from tasks where " - "state = 0 and platform = '%s'", esc_plat); - if (sqlite3_exec(pdb, query, sql3_get_integer_cb, - &pending_count, NULL) != SQLITE_OK) { + "state = 0 and platform = '%s'", esc_plat); + m = sqlite3_exec(pdb, query, sql3_get_integer_cb, &pending_count, NULL); + + if (m != SQLITE_OK) { pending_count = 0; - lwsl_err("%s: query failed\n", __func__); + lwsl_err("%s: query failed: %d\n", __func__, m); } - if (pending_count > 0) { lws_sql_purify(esc_repo, e->repo_name, sizeof(esc_repo)); @@ -387,7 +403,7 @@ sais_task_pending(struct vhd *vhd, struct pss *pss, const char *platform) } while (1); if (checked_uuid[0]) { - lwsl_notice("%s: checked_uuid %s\n", __func__, checked_uuid); + // lwsl_notice("%s: checked_uuid %s\n", __func__, checked_uuid); if (!sais_event_db_ensure_open(vhd, checked_uuid, 1, &prev_pdb)) { sqlite3_stmt *sm; @@ -435,7 +451,8 @@ sais_task_pending(struct vhd *vhd, struct pss *pss, const char *platform) sais_event_db_close(vhd, &prev_pdb); } else lwsl_err("%s: unable to open %s\n", __func__, checked_uuid); - } + } else + lwsl_notice("%s: platform %s: no checked uuid\n", __func__, platform); /* * Let's go through the tasks that failed last time we built this repo / branch, and see @@ -464,6 +481,9 @@ sais_task_pending(struct vhd *vhd, struct pss *pss, const char *platform) lwsac_free(&failed_ac); memcpy(&pss->alloc_task, lws_container_of( owner.head, sai_task_t, list), sizeof(pss->alloc_task)); + + lwsl_notice("%s: platform %s: returning selected task\n", __func__, platform); + return &pss->alloc_task; } } lws_end_foreach_dll(p_fail); @@ -487,9 +507,15 @@ sais_task_pending(struct vhd *vhd, struct pss *pss, const char *platform) lwsac_free(&failed_ac); memcpy(&pss->alloc_task, lws_container_of( owner.head, sai_task_t, list), sizeof(pss->alloc_task)); + + lwsl_notice("%s: platform %s: returning fallback task\n", __func__, platform); + return &pss->alloc_task; } - } + } // else + // lwsl_notice("%s: platform %s: no pending count\n", __func__, platform); + + sais_event_db_close(vhd, &pdb); } } lws_end_foreach_dll(p); diff --git a/src/server/s-ws-builder.c b/src/server/s-ws-builder.c index 0c4956c..15ae7ea 100644 --- a/src/server/s-ws-builder.c +++ b/src/server/s-ws-builder.c @@ -376,9 +376,19 @@ handle: } /* + * It's a reconnect, update connection-specific things + */ + + cb->wsi = pss->wsi; + + if (pss->peer_ip[0]) + lws_strncpy(cb->peer_ip, pss->peer_ip, sizeof(cb->peer_ip)); + + /* * Even if he's not new, we should use his updated info about * builder load */ + cb->ongoing = build->ongoing; cb->instances = build->instances;