@@ -20,38 +20,39 @@ class Ingestor
20
20
LOW_QUEUE_LENGTH = 3
21
21
FIELD_REF = /%\{ [^}]+\} /
22
22
23
- def initialize ( ingest_url , app_id , app_key , app_tenant , managed_identity_id , cli_auth , database , table , json_mapping , proxy_host , proxy_port , proxy_protocol , logger , threadpool = DEFAULT_THREADPOOL )
23
+ def initialize ( kusto_logstash_configuration , logger , threadpool = DEFAULT_THREADPOOL )
24
24
@workers_pool = threadpool
25
25
@logger = logger
26
- validate_config ( database , table , json_mapping , proxy_protocol , app_id , app_key , managed_identity_id , cli_auth )
26
+ #Validate and assign
27
+ kusto_logstash_configuration . validate_config ( )
28
+ @kusto_logstash_configuration = kusto_logstash_configuration
29
+
27
30
@logger . info ( 'Preparing Kusto resources.' )
28
31
29
32
kusto_java = Java ::com . microsoft . azure . kusto
30
33
apache_http = Java ::org . apache . http
31
- # kusto_connection_string = kusto_java.data.auth.ConnectionStringBuilder.createWithAadApplicationCredentials(ingest_url, app_id, app_key.value, app_tenant)
32
- # If there is managed identity, use it. This means the AppId and AppKey are empty/nil
33
- # If there is CLI Auth, use that instead of managed identity
34
- is_managed_identity = ( app_id . nil? && app_key . nil? && !cli_auth )
34
+
35
+ is_managed_identity = @kusto_logstash_configuration . kusto_auth . is_managed_identity
35
36
# If it is system managed identity, propagate the system identity
36
- is_system_assigned_managed_identity = is_managed_identity && 0 == "system" . casecmp ( managed_identity_id )
37
+ is_system_assigned_managed_identity = @kusto_logstash_configuration . kusto_auth . is_system_assigned_managed_identity
37
38
# Is it direct connection
38
- is_direct_conn = ( proxy_host . nil? || proxy_host . empty? )
39
+ is_direct_conn = @kusto_logstash_configuration . kusto_proxy . is_direct_conn
39
40
# Create a connection string
40
41
kusto_connection_string = if is_managed_identity
41
42
if is_system_assigned_managed_identity
42
43
@logger . info ( 'Using system managed identity.' )
43
- kusto_java . data . auth . ConnectionStringBuilder . createWithAadManagedIdentity ( ingest_url )
44
+ kusto_java . data . auth . ConnectionStringBuilder . createWithAadManagedIdentity ( @kusto_logstash_configuration . kusto_ingest . ingest_url )
44
45
else
45
46
@logger . info ( 'Using user managed identity.' )
46
- kusto_java . data . auth . ConnectionStringBuilder . createWithAadManagedIdentity ( ingest_url , managed_identity_id )
47
+ kusto_java . data . auth . ConnectionStringBuilder . createWithAadManagedIdentity ( @kusto_logstash_configuration . kusto_ingest . ingest_url , @kusto_logstash_configuration . kusto_ingest . managed_identity_id )
47
48
end
48
49
else
49
- if cli_auth
50
+ if @kusto_logstash_configuration . kusto_auth . cli_auth
50
51
@logger . warn ( '*Use of CLI Auth is only for dev-test scenarios. This is ***NOT RECOMMENDED*** for production*' )
51
- kusto_java . data . auth . ConnectionStringBuilder . createWithAzureCli ( ingest_url )
52
+ kusto_java . data . auth . ConnectionStringBuilder . createWithAzureCli ( @kusto_logstash_configuration . kusto_ingest . ingest_url )
52
53
else
53
54
@logger . info ( 'Using app id and app key.' )
54
- kusto_java . data . auth . ConnectionStringBuilder . createWithAadApplicationCredentials ( ingest_url , app_id , app_key . value , app_tenant )
55
+ kusto_java . data . auth . ConnectionStringBuilder . createWithAadApplicationCredentials ( @kusto_logstash_configuration . kusto_ingest . ingest_url , @kusto_logstash_configuration . kusto_auth . app_id , @kusto_logstash_configuration . kusto_auth . app_key . value , @kusto_logstash_configuration . kusto_auth . app_tenant )
55
56
end
56
57
end
57
58
@logger . debug ( Gem . loaded_specs . to_s )
@@ -62,22 +63,22 @@ def initialize(ingest_url, app_id, app_key, app_tenant, managed_identity_id, cli
62
63
tuple_utils = Java ::org . apache . commons . lang3 . tuple
63
64
# kusto_connection_string.setClientVersionForTracing(name_for_tracing)
64
65
version_for_tracing = Gem . loaded_specs [ 'logstash-output-kusto' ] &.version || "unknown"
65
- kusto_connection_string . setConnectorDetails ( "Logstash" , version_for_tracing . to_s , "" , "" , false , "" , tuple_utils . Pair . emptyArray ( ) ) ;
66
+ kusto_connection_string . setConnectorDetails ( "Logstash" , version_for_tracing . to_s , name_for_tracing . to_s , version_for_tracing . to_s , false , "" , tuple_utils . Pair . emptyArray ( ) ) ;
66
67
67
68
@kusto_client = begin
68
69
if is_direct_conn
69
70
kusto_java . ingest . IngestClientFactory . createClient ( kusto_connection_string )
70
71
else
71
- kusto_http_client_properties = kusto_java . data . HttpClientProperties . builder ( ) . proxy ( apache_http . HttpHost . new ( proxy_host , proxy_port , proxy_protocol ) ) . build ( )
72
+ kusto_http_client_properties = kusto_java . data . HttpClientProperties . builder ( ) . proxy ( apache_http . HttpHost . new ( @kusto_logstash_configuration . kusto_proxy . proxy_host , @kusto_logstash_configuration . kusto_proxy . proxy_port , @kusto_logstash_configuration . kusto_proxy . proxy_protocol ) ) . build ( )
72
73
kusto_java . ingest . IngestClientFactory . createClient ( kusto_connection_string , kusto_http_client_properties )
73
74
end
74
75
end
75
76
76
- @ingestion_properties = kusto_java . ingest . IngestionProperties . new ( database , table )
77
- is_mapping_ref_provided = ! ( json_mapping . nil? || json_mapping . empty? )
78
- if is_mapping_ref_provided
79
- @logger . debug ( 'Using mapping reference.' , json_mapping )
80
- @ingestion_properties . setIngestionMapping ( json_mapping , kusto_java . ingest . IngestionMapping ::IngestionMappingKind ::JSON )
77
+ @ingestion_properties = kusto_java . ingest . IngestionProperties . new ( @kusto_logstash_configuration . kusto_ingest . database , @kusto_logstash_configuration . kusto_ingest . table )
78
+
79
+ if @kusto_logstash_configuration . kusto_ingest . is_mapping_ref_provided
80
+ @logger . debug ( 'Using mapping reference.' , @kusto_logstash_configuration . kusto_ingest . json_mapping )
81
+ @ingestion_properties . setIngestionMapping ( @kusto_logstash_configuration . kusto_ingest . json_mapping , kusto_java . ingest . IngestionMapping ::IngestionMappingKind ::JSON )
81
82
@ingestion_properties . setDataFormat ( kusto_java . ingest . IngestionProperties ::DataFormat ::JSON )
82
83
else
83
84
@logger . debug ( 'No mapping reference provided. Columns will be mapped by names in the logstash output' )
@@ -86,38 +87,6 @@ def initialize(ingest_url, app_id, app_key, app_tenant, managed_identity_id, cli
86
87
@logger . debug ( 'Kusto resources are ready.' )
87
88
end
88
89
89
- def validate_config ( database , table , json_mapping , proxy_protocol , app_id , app_key , managed_identity_id , cli_auth )
90
- # Add an additional validation and fail this upfront
91
- if app_id . nil? && app_key . nil? && managed_identity_id . nil?
92
- if cli_auth
93
- @logger . info ( 'Using CLI Auth, this is only for dev-test scenarios. This is ***NOT RECOMMENDED*** for production' )
94
- else
95
- @logger . error ( 'managed_identity_id is not provided and app_id/app_key is empty.' )
96
- raise LogStash ::ConfigurationError . new ( 'managed_identity_id is not provided and app_id/app_key is empty.' )
97
- end
98
- end
99
- if database =~ FIELD_REF
100
- @logger . error ( 'database config value should not be dynamic.' , database )
101
- raise LogStash ::ConfigurationError . new ( 'database config value should not be dynamic.' )
102
- end
103
-
104
- if table =~ FIELD_REF
105
- @logger . error ( 'table config value should not be dynamic.' , table )
106
- raise LogStash ::ConfigurationError . new ( 'table config value should not be dynamic.' )
107
- end
108
-
109
- if json_mapping =~ FIELD_REF
110
- @logger . error ( 'json_mapping config value should not be dynamic.' , json_mapping )
111
- raise LogStash ::ConfigurationError . new ( 'json_mapping config value should not be dynamic.' )
112
- end
113
-
114
- if not( [ "https" , "http" ] . include? proxy_protocol )
115
- @logger . error ( 'proxy_protocol has to be http or https.' , proxy_protocol )
116
- raise LogStash ::ConfigurationError . new ( 'proxy_protocol has to be http or https.' )
117
- end
118
-
119
- end
120
-
121
90
def upload_async ( data )
122
91
if @workers_pool . remaining_capacity <= LOW_QUEUE_LENGTH
123
92
@logger . warn ( "Ingestor queue capacity is running low with #{ @workers_pool . remaining_capacity } free slots." )
0 commit comments