Skip to content

Commit 288a924

Browse files
authored
dynamic_modules: added host information callbacks for dynamic module clusters LB (#43875)
## Description This PR adds host information callbacks for dynamic module cluster load balancers, providing parity with the standalone load balancer's host information API. This includes host address, weight, health, locality, metadata, active requests/connections, per-host counter stats, host data get/set, and locality-aware routing callbacks. --- **Commit Message:** dynamic_modules: added host information callbacks for dynamic module clusters LB **Additional Description:** Added host information callbacks for dynamic module cluster load balancers **Risk Level:** Low **Testing:** Added Tests **Docs Changes:** Added **Release Notes:** N/A Signed-off-by: Rohit Agrawal <rohit.agrawal@databricks.com>
1 parent c4dcca9 commit 288a924

File tree

14 files changed

+2275
-236
lines changed

14 files changed

+2275
-236
lines changed

source/extensions/clusters/dynamic_modules/abi_impl.cc

Lines changed: 463 additions & 8 deletions
Large diffs are not rendered by default.

source/extensions/clusters/dynamic_modules/cluster.cc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,42 @@ const Upstream::PrioritySet& DynamicModuleLoadBalancer::prioritySet() const {
409409
return handle_->cluster_->prioritySet();
410410
}
411411

412+
bool DynamicModuleLoadBalancer::setHostData(uint32_t priority, size_t index, uintptr_t data) {
413+
const auto& host_sets = prioritySet().hostSetsPerPriority();
414+
if (priority >= host_sets.size()) {
415+
return false;
416+
}
417+
const auto& hosts = host_sets[priority]->hosts();
418+
if (index >= hosts.size()) {
419+
return false;
420+
}
421+
if (data == 0) {
422+
per_host_data_.erase({priority, index});
423+
} else {
424+
per_host_data_[{priority, index}] = data;
425+
}
426+
return true;
427+
}
428+
429+
bool DynamicModuleLoadBalancer::getHostData(uint32_t priority, size_t index,
430+
uintptr_t* data) const {
431+
const auto& host_sets = prioritySet().hostSetsPerPriority();
432+
if (priority >= host_sets.size()) {
433+
return false;
434+
}
435+
const auto& hosts = host_sets[priority]->hosts();
436+
if (index >= hosts.size()) {
437+
return false;
438+
}
439+
auto it = per_host_data_.find({priority, index});
440+
if (it != per_host_data_.end()) {
441+
*data = it->second;
442+
} else {
443+
*data = 0;
444+
}
445+
return true;
446+
}
447+
412448
// =================================================================================================
413449
// DynamicModuleClusterFactory
414450
// =================================================================================================

source/extensions/clusters/dynamic_modules/cluster.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,16 @@ class DynamicModuleLoadBalancer : public Upstream::LoadBalancer {
446446
// Access the handle for async host selection completion.
447447
const DynamicModuleClusterHandleSharedPtr& handle() const { return handle_; }
448448

449+
// Per-host custom data storage.
450+
bool setHostData(uint32_t priority, size_t index, uintptr_t data);
451+
bool getHostData(uint32_t priority, size_t index, uintptr_t* data) const;
452+
449453
private:
450454
const DynamicModuleClusterHandleSharedPtr handle_;
451455
envoy_dynamic_module_type_cluster_lb_module_ptr in_module_lb_;
456+
457+
// Per-host data storage keyed by (priority, index). This is per-LB-instance (per-worker).
458+
absl::flat_hash_map<std::pair<uint32_t, size_t>, uintptr_t> per_host_data_;
452459
};
453460

454461
/**

source/extensions/dynamic_modules/abi/abi.h

Lines changed: 354 additions & 65 deletions
Large diffs are not rendered by default.

source/extensions/dynamic_modules/abi_impl.cc

Lines changed: 161 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,164 @@ envoy_dynamic_module_callback_cluster_lb_get_healthy_host(
396396
return nullptr;
397397
}
398398

399+
__attribute__((weak)) void envoy_dynamic_module_callback_cluster_lb_get_cluster_name(
400+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, envoy_dynamic_module_type_envoy_buffer*) {
401+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_cluster_name: "
402+
"not implemented in this context");
403+
}
404+
405+
__attribute__((weak)) size_t envoy_dynamic_module_callback_cluster_lb_get_hosts_count(
406+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, uint32_t) {
407+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_hosts_count: "
408+
"not implemented in this context");
409+
return 0;
410+
}
411+
412+
__attribute__((weak)) size_t envoy_dynamic_module_callback_cluster_lb_get_degraded_hosts_count(
413+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, uint32_t) {
414+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_degraded_hosts_count: "
415+
"not implemented in this context");
416+
return 0;
417+
}
418+
419+
__attribute__((weak)) size_t envoy_dynamic_module_callback_cluster_lb_get_priority_set_size(
420+
envoy_dynamic_module_type_cluster_lb_envoy_ptr) {
421+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_priority_set_size: "
422+
"not implemented in this context");
423+
return 0;
424+
}
425+
426+
__attribute__((weak)) bool envoy_dynamic_module_callback_cluster_lb_get_healthy_host_address(
427+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, uint32_t, size_t,
428+
envoy_dynamic_module_type_envoy_buffer*) {
429+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_healthy_host_address: "
430+
"not implemented in this context");
431+
return false;
432+
}
433+
434+
__attribute__((weak)) uint32_t envoy_dynamic_module_callback_cluster_lb_get_healthy_host_weight(
435+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, uint32_t, size_t) {
436+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_healthy_host_weight: "
437+
"not implemented in this context");
438+
return 0;
439+
}
440+
441+
__attribute__((weak)) envoy_dynamic_module_type_host_health
442+
envoy_dynamic_module_callback_cluster_lb_get_host_health(
443+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, uint32_t, size_t) {
444+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_host_health: "
445+
"not implemented in this context");
446+
return envoy_dynamic_module_type_host_health_Unhealthy;
447+
}
448+
449+
__attribute__((weak)) bool envoy_dynamic_module_callback_cluster_lb_get_host_health_by_address(
450+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, envoy_dynamic_module_type_module_buffer,
451+
envoy_dynamic_module_type_host_health*) {
452+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_host_health_by_address: "
453+
"not implemented in this context");
454+
return false;
455+
}
456+
457+
__attribute__((weak)) bool envoy_dynamic_module_callback_cluster_lb_get_host_address(
458+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, uint32_t, size_t,
459+
envoy_dynamic_module_type_envoy_buffer*) {
460+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_host_address: "
461+
"not implemented in this context");
462+
return false;
463+
}
464+
465+
__attribute__((weak)) uint32_t envoy_dynamic_module_callback_cluster_lb_get_host_weight(
466+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, uint32_t, size_t) {
467+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_host_weight: "
468+
"not implemented in this context");
469+
return 0;
470+
}
471+
472+
__attribute__((weak)) uint64_t envoy_dynamic_module_callback_cluster_lb_get_host_stat(
473+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, uint32_t, size_t,
474+
envoy_dynamic_module_type_host_stat) {
475+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_host_stat: "
476+
"not implemented in this context");
477+
return 0;
478+
}
479+
480+
__attribute__((weak)) bool envoy_dynamic_module_callback_cluster_lb_get_host_locality(
481+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, uint32_t, size_t,
482+
envoy_dynamic_module_type_envoy_buffer*, envoy_dynamic_module_type_envoy_buffer*,
483+
envoy_dynamic_module_type_envoy_buffer*) {
484+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_host_locality: "
485+
"not implemented in this context");
486+
return false;
487+
}
488+
489+
__attribute__((weak)) bool envoy_dynamic_module_callback_cluster_lb_set_host_data(
490+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, uint32_t, size_t, uintptr_t) {
491+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_set_host_data: "
492+
"not implemented in this context");
493+
return false;
494+
}
495+
496+
__attribute__((weak)) bool envoy_dynamic_module_callback_cluster_lb_get_host_data(
497+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, uint32_t, size_t, uintptr_t*) {
498+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_host_data: "
499+
"not implemented in this context");
500+
return false;
501+
}
502+
503+
__attribute__((weak)) bool envoy_dynamic_module_callback_cluster_lb_get_host_metadata_string(
504+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, uint32_t, size_t,
505+
envoy_dynamic_module_type_module_buffer, envoy_dynamic_module_type_module_buffer,
506+
envoy_dynamic_module_type_envoy_buffer*) {
507+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_host_metadata_string: "
508+
"not implemented in this context");
509+
return false;
510+
}
511+
512+
__attribute__((weak)) bool envoy_dynamic_module_callback_cluster_lb_get_host_metadata_number(
513+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, uint32_t, size_t,
514+
envoy_dynamic_module_type_module_buffer, envoy_dynamic_module_type_module_buffer, double*) {
515+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_host_metadata_number: "
516+
"not implemented in this context");
517+
return false;
518+
}
519+
520+
__attribute__((weak)) bool envoy_dynamic_module_callback_cluster_lb_get_host_metadata_bool(
521+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, uint32_t, size_t,
522+
envoy_dynamic_module_type_module_buffer, envoy_dynamic_module_type_module_buffer, bool*) {
523+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_host_metadata_bool: "
524+
"not implemented in this context");
525+
return false;
526+
}
527+
528+
__attribute__((weak)) size_t envoy_dynamic_module_callback_cluster_lb_get_locality_count(
529+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, uint32_t) {
530+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_locality_count: "
531+
"not implemented in this context");
532+
return 0;
533+
}
534+
535+
__attribute__((weak)) size_t envoy_dynamic_module_callback_cluster_lb_get_locality_host_count(
536+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, uint32_t, size_t) {
537+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_locality_host_count: "
538+
"not implemented in this context");
539+
return 0;
540+
}
541+
542+
__attribute__((weak)) bool envoy_dynamic_module_callback_cluster_lb_get_locality_host_address(
543+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, uint32_t, size_t, size_t,
544+
envoy_dynamic_module_type_envoy_buffer*) {
545+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_locality_host_address: "
546+
"not implemented in this context");
547+
return false;
548+
}
549+
550+
__attribute__((weak)) uint32_t envoy_dynamic_module_callback_cluster_lb_get_locality_weight(
551+
envoy_dynamic_module_type_cluster_lb_envoy_ptr, uint32_t, size_t) {
552+
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_get_locality_weight: "
553+
"not implemented in this context");
554+
return 0;
555+
}
556+
399557
__attribute__((weak)) bool envoy_dynamic_module_callback_cluster_lb_context_compute_hash_key(
400558
envoy_dynamic_module_type_cluster_lb_context_envoy_ptr, uint64_t*) {
401559
IS_ENVOY_BUG("envoy_dynamic_module_callback_cluster_lb_context_compute_hash_key: "
@@ -646,20 +804,6 @@ __attribute__((weak)) uint32_t envoy_dynamic_module_callback_lb_get_host_weight(
646804
return 0;
647805
}
648806

649-
__attribute__((weak)) uint64_t envoy_dynamic_module_callback_lb_get_host_active_requests(
650-
envoy_dynamic_module_type_lb_envoy_ptr, uint32_t, size_t) {
651-
IS_ENVOY_BUG("envoy_dynamic_module_callback_lb_get_host_active_requests: "
652-
"not implemented in this context");
653-
return 0;
654-
}
655-
656-
__attribute__((weak)) uint64_t envoy_dynamic_module_callback_lb_get_host_active_connections(
657-
envoy_dynamic_module_type_lb_envoy_ptr, uint32_t, size_t) {
658-
IS_ENVOY_BUG("envoy_dynamic_module_callback_lb_get_host_active_connections: "
659-
"not implemented in this context");
660-
return 0;
661-
}
662-
663807
__attribute__((weak)) bool
664808
envoy_dynamic_module_callback_lb_get_host_locality(envoy_dynamic_module_type_lb_envoy_ptr, uint32_t,
665809
size_t, envoy_dynamic_module_type_envoy_buffer*,
@@ -800,11 +944,9 @@ __attribute__((weak)) bool envoy_dynamic_module_callback_lb_get_member_update_ho
800944
return false;
801945
}
802946

803-
__attribute__((weak)) uint64_t envoy_dynamic_module_callback_lb_get_host_counter_stat(
804-
envoy_dynamic_module_type_lb_envoy_ptr, uint32_t, size_t,
805-
envoy_dynamic_module_type_host_counter_stat) {
806-
IS_ENVOY_BUG("envoy_dynamic_module_callback_lb_get_host_counter_stat: "
807-
"not implemented in this context");
947+
__attribute__((weak)) uint64_t envoy_dynamic_module_callback_lb_get_host_stat(
948+
envoy_dynamic_module_type_lb_envoy_ptr, uint32_t, size_t, envoy_dynamic_module_type_host_stat) {
949+
IS_ENVOY_BUG("envoy_dynamic_module_callback_lb_get_host_stat: not implemented in this context");
808950
return 0;
809951
}
810952

0 commit comments

Comments
 (0)