@@ -943,6 +943,54 @@ static int cb_azure_kusto_init(struct flb_output_instance *ins, struct flb_confi
943943 return -1 ;
944944 }
945945
946+ /*
947+ * Create upstream context for Kusto Cluster endpoint (for streaming ingestion)
948+ * Convert ingestion endpoint to cluster endpoint by removing "ingest-" prefix
949+ */
950+ if (ctx -> streaming_ingestion_enabled == FLB_TRUE ) {
951+ flb_sds_t cluster_endpoint = NULL ;
952+
953+ /* Check if ingestion endpoint contains "ingest-" prefix */
954+ if (strstr (ctx -> ingestion_endpoint , "ingest-" ) != NULL ) {
955+ /* Create cluster endpoint by removing "ingest-" prefix */
956+ cluster_endpoint = flb_sds_create (ctx -> ingestion_endpoint );
957+ if (!cluster_endpoint ) {
958+ flb_plg_error (ctx -> ins , "failed to create cluster endpoint string" );
959+ return -1 ;
960+ }
961+
962+ /* Replace "ingest-" with empty string to get cluster endpoint */
963+ char * ingest_pos = strstr (cluster_endpoint , "ingest-" );
964+ if (ingest_pos ) {
965+ /* Move the rest of the string to remove "ingest-" */
966+ memmove (ingest_pos , ingest_pos + 7 , strlen (ingest_pos + 7 ) + 1 );
967+ flb_sds_len_set (cluster_endpoint , flb_sds_len (cluster_endpoint ) - 7 );
968+ }
969+
970+ flb_plg_info (ctx -> ins , "Creating cluster upstream connection to: %s" , cluster_endpoint );
971+
972+ /* Create upstream connection to cluster endpoint */
973+ ctx -> u_cluster = flb_upstream_create_url (config , cluster_endpoint , io_flags , ins -> tls );
974+ if (!ctx -> u_cluster ) {
975+ flb_plg_error (ctx -> ins , "cluster upstream creation failed for endpoint: %s" , cluster_endpoint );
976+ flb_sds_destroy (cluster_endpoint );
977+ return -1 ;
978+ }
979+
980+ flb_sds_destroy (cluster_endpoint );
981+ } else {
982+ flb_plg_warn (ctx -> ins , "ingestion endpoint does not contain 'ingest-' prefix, using as cluster endpoint" );
983+ /* Use ingestion endpoint directly as cluster endpoint */
984+ ctx -> u_cluster = flb_upstream_create_url (config , ctx -> ingestion_endpoint , io_flags , ins -> tls );
985+ if (!ctx -> u_cluster ) {
986+ flb_plg_error (ctx -> ins , "cluster upstream creation failed" );
987+ return -1 ;
988+ }
989+ }
990+
991+ flb_plg_info (ctx -> ins , "Cluster upstream connection created successfully for streaming ingestion" );
992+ }
993+
946994 flb_plg_debug (ctx -> ins , "async flag is %d" , flb_stream_is_async (& ctx -> u -> base ));
947995
948996 /* Create oauth2 context */
@@ -1529,6 +1577,11 @@ static int cb_azure_kusto_exit(void *data, struct flb_config *config)
15291577 ctx -> u = NULL ;
15301578 }
15311579
1580+ if (ctx -> u_cluster ) {
1581+ flb_upstream_destroy (ctx -> u_cluster );
1582+ ctx -> u_cluster = NULL ;
1583+ }
1584+
15321585 pthread_mutex_destroy (& ctx -> resources_mutex );
15331586 pthread_mutex_destroy (& ctx -> token_mutex );
15341587 pthread_mutex_destroy (& ctx -> blob_mutex );
0 commit comments