KQL Performance Optimization

%3CLINGO-SUB%20id%3D%22lingo-sub-1532684%22%20slang%3D%22en-US%22%3EKQL%20Performance%20Optimization%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1532684%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHello%20folks%2C%3C%2FP%3E%3CP%3EI%20am%20building%26nbsp%3B%20query%20that%20basically%20does%20the%20following%20%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1-%26nbsp%3B%20Extend%20and%20Project%20fields%20from%20Table1%2C%20which%20contains%20syslogs%3C%2FP%3E%3CP%3E2-%20Summarize%20table%20fields%20mentioned%20in%20(1)%3C%2FP%3E%3CP%3E3-%20Join%20the%20summarized%20table%20with%20a%20static%20datatable%20(Table2)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20performance%20is%20poor%2C%20it%20frequently%20hits%20the%2010%20minutes%20limits.%20I%20did%20troubleshooting%20by%20isolation%3B%20decomposing%20the%20query%20into%20sub-queries%20to%20pinpoint%20the%20problematic%20part%2C%20and%20found%20it's%20the%20summarize%20line!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EActing%20on%20the%20same%20dataset%3A%20Extend%2FProject%20operations%20take%20few%20seconds%2C%20JOIN%20takes%20few%20seconds%2C%20Summarize%20hits%20the%2010%20mins%20limit%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EQUESTION1%3A%20What%20are%20the%20options%20to%20improve%20the%20performance%20of%20the%20Summarize%20operation%3F%20I%20tried%20hint.strategy%3Dshuffle%20but%20it%20didn't%20change%20the%20situation.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EQUESTION2%3A%20How%20to%20review%2Fconfirm%20the%20settings%20of%20Data%20Partitioning%20Policy%20and%20Shuffle%20strategy%26nbsp%3B%20in%20Sentinel%20%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETried%20both%20lines%3A%3C%2FP%3E%3CP%3E%3CSPAN%3E%7C%20%3C%2FSPAN%3E%3CSPAN%3Esummarize%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3Ecount%3C%2FSPAN%3E%3CSPAN%3E()%20%3C%2FSPAN%3E%3CSPAN%3Eby%3C%2FSPAN%3E%3CSPAN%3E%20app%3B%3C%2FSPAN%3E%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%7C%20%3C%2FSPAN%3E%3CSPAN%3Esummarize%3C%2FSPAN%3E%3CSPAN%3E%20hint.strategy%3Dshuffle%20%3C%2FSPAN%3E%3CSPAN%3Ecount%3C%2FSPAN%3E%3CSPAN%3E()%20%3C%2FSPAN%3E%3CSPAN%3Eby%3C%2FSPAN%3E%3CSPAN%3E%20app%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1533062%22%20slang%3D%22en-US%22%3ERe%3A%20KQL%20Performance%20Optimization%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1533062%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F540154%22%20target%3D%22_blank%22%3E%40majo01%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20suspect%20you%20have%20read%20this%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fdata-explorer%2Fkusto%2Fquery%2Fbest-practices%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fdata-explorer%2Fkusto%2Fquery%2Fbest-practices%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIs%20the%20summarize%20that's%20having%20the%20issue%20within%20the%20Join%20or%20outside%20the%20join%3F%26nbsp%3B%20If%20the%20data%20is%20Syslog%2C%20I%20assume%20its%20the%20%3CSTRONG%3ESyslog%3C%2FSTRONG%3E%20table%20and%20you%20have%20that%20on%20the%20right%20of%20the%20join%20-%20see%20link%20above%26nbsp%3B%20(the%20datatable%20being%20the%20smaller%20table%20on%20the%20left%3F).%26nbsp%3B%20Are%20you%20able%20to%20reduce%20the%20data%20from%20syslog%2C%20maybe%20use%20a%20%3CSTRONG%3Ebin%3C%2FSTRONG%3E%20if%20its%20across%20many%20hours%20or%20days%3F%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3ECan%20you%20offer%20a%20sample%20of%20the%20datatable%20and%20Syslog%20syntax%3F%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1535215%22%20slang%3D%22en-US%22%3ERe%3A%20KQL%20Performance%20Optimization%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1535215%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F239477%22%20target%3D%22_blank%22%3E%40Clive%20Watson%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYes%2C%20i%20read%20it.%3C%2FP%3E%3CP%3ESummarize%20is%20outside%20the%20JOIN%2C%20and%26nbsp%3B%20i%20confirmed%20that%20it's%20the%20culprit%2C%20not%20the%20JOIN.%20Any%20ideas%20to%20improve%20the%20performance%20of%20JOIN%2C%20given%20that%20the%20dataset%20it's%20acting%20on%20it%20very%20huge%20(tens%20of%20millions%20of%20logs).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%2F%2FPART1%3A%20Logs%20preparation%2C%20note%20that%20syslog1%20is%20a%20function%20created%20elsewhere%3A%3C%2FP%3E%3CP%3ESyslog1%3C%2FP%3E%3CP%3E%7C%20where%20TimeGenerated%20%26gt%3B%20startDatetime%20and%20TimeGenerated%20%26lt%3B%20endDatetime%3CBR%20%2F%3E%7C%20where%20Activity%20%3D%3D%20%22TRAFFIC%22%20or%20Activity%20%3D%3D%20%22THREAT%22%3C%2FP%3E%3CP%3E%7C%20project-rename%20signature%20%3D%20ThreatName%3CBR%20%2F%3E%7C%20project-rename%20threat_category%20%3D%20ThreatCategory%3CBR%20%2F%3E%7C%20project-rename%20category%3D%20ThreatType%2C%20severity%20%3D%20SeverityLevel%2C%20action%20%3D%20DeviceAction%2C%20content_version%20%3D%20ContentVersion%3C%2FP%3E%3CP%3E%7C%20extend%20app%20%3D%20tostring(Application)%2C%20day%20%3D%20dayofmonth(TimeGenerated)%2C%20month%20%3D%20getmonth(TimeGenerated)%2C%20year%20%3D%20getyear(TimeGenerated)%3CBR%20%2F%3E%7C%20extend%20traffic%20%3D%20toint(Bytes)%3CBR%20%2F%3E%7C%20extend%20parsed_src_IP%20%3D%20parse_ipv4(SourceIP)%3CBR%20%2F%3E%7C%20extend%20src_zone%20%3D%20case(parsed_src_IP%20between%20(%20parse_ipv4(%22192.168.0.0%22)%20..%20parse_ipv4(%22192.168.255%22)%20)%2C%22Guest%22%2C%3CBR%20%2F%3Eparsed_src_IP%20between%20(%20parse_ipv4(%22127.0.0.0%22)%20..%20parse_ipv4(%22127.0.0.1%22)%20)%2C%22Corporate%22%2C%3CBR%20%2F%3Eparsed_src_IP%20between%20(%20parse_ipv4(%2210.0.0.0%22)%20..%20parse_ipv4(%2210.255.255.255%22)%20)%2C%22Corporate%22%2C%3CBR%20%2F%3Eparsed_src_IP%20between%20(%20parse_ipv4(%22172.16.0.0%22)%20..%20parse_ipv4(%22172.31.255.255%22)%20)%2C%22Corporate%22%2C%3CBR%20%2F%3E%2F%2Felse%3CBR%20%2F%3E%22Public%22)%3CBR%20%2F%3E%7C%20extend%20parsed_dst_IP%20%3D%20parse_ipv4(DestinationIP)%3CBR%20%2F%3E%7C%20extend%20dst_zone%20%3D%20case(parsed_dst_IP%20between%20(%20parse_ipv4(%22192.168.0.0%22)%20..%20parse_ipv4(%22192.168.255%22)%20)%2C%22Guest%22%2C%3CBR%20%2F%3Eparsed_dst_IP%20between%20(%20parse_ipv4(%22127.0.0.0%22)%20..%20parse_ipv4(%22127.0.0.1%22)%20)%2C%22Corporate%22%2C%3CBR%20%2F%3Eparsed_dst_IP%20between%20(%20parse_ipv4(%2210.0.0.0%22)%20..%20parse_ipv4(%2210.255.255.255%22)%20)%2C%22Corporate%22%2C%3CBR%20%2F%3Eparsed_dst_IP%20between%20(%20parse_ipv4(%22172.16.0.0%22)%20..%20parse_ipv4(%22172.31.255.255%22)%20)%2C%22Corporate%22%2C%3CBR%20%2F%3E%2F%2Felse%3CBR%20%2F%3E%22Public%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%2F%2F%20Problematic%20Part%20which%20is%20the%20following%20summarize%20statement%3C%2FP%3E%3CP%3E%7C%20summarize%20sum(traffic)%2C%20count(app)%20by%20app%2C%20src_zone%2C%20dst_zone%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%2F%2F%20PART3%3A%3C%2FP%3E%3CP%3EJOIN%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1550085%22%20slang%3D%22en-US%22%3ERe%3A%20KQL%20Performance%20Optimization%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1550085%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F540154%22%20target%3D%22_blank%22%3E%40majo01%3C%2FA%3E%26nbsp%3B%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20think%20there%20is%20little%20to%20do%20with%20%22summarize%22%20beyond%20shuffle.%20Is%20the%20performance%20prior%20to%20summarize%20reasonable%3F%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOne%20option%20is%20to%20filter%20before%20parsing.%20If%20it%20is%20easy%20to%20check%20Activity%20on%20raw%20syslog%2C%20it%20should%20accelerate%20things%20considerably.%20I%20woudl%20first%20check%20by%20including%20the%20parser%20in%20the%20query.%20If%20it%20works%2C%20the%20parser%20can%20be%20omdified%20to%20be%20a%20parameter%20function%20that%20can%20be%20applied%20after%20initial%20filtering.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1565916%22%20slang%3D%22en-US%22%3ERe%3A%20KQL%20Performance%20Optimization%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1565916%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F293879%22%20target%3D%22_blank%22%3E%40Ofer_Shezaf%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20a%20bit%20to%20make%20a%20parser%20as%20parameter%20function%2C%20something%20is%20going%20wrong.%20How%20can%20we%20call%20the%20tabular%20parameter%20from%20within%20the%20function%20%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBelow%20is%20sample%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%2F%2FPART1%3A%20prepare%20the%20filtered%20dataset%20that's%20to%20be%20passed%20to%20the%20parser%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3Elet%20filteredDataSet%20%3D%20Syslog%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7C%20%3C%2FSPAN%3E%3CSPAN%3Ewhere%3C%2FSPAN%3E%3CSPAN%3E%20SyslogMessage%20%3C%2FSPAN%3E%3CSPAN%3Econtains%3C%2FSPAN%3E%20%3CSPAN%3E%22%2CTRAFFIC%2C%22%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F%2FPART2%3A%20the%20p%3C%2FSPAN%3Earameterized%20function%20with%20tablular%20parameter.%20The%20function%20will%20perform%20Extend%2FProject%20actions%20on%20the%20table%20%2F%20message%20passed%20to%20it%20as%20parameter%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3Elet%20parserFunc%20%3D%20(T%3C%2FSPAN%3E%3CSPAN%3E%3A%3C%2FSPAN%3E%3CSPAN%3E(*)%20)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ET%20%7C%20%3C%2FSPAN%3E%3CSPAN%3Eextend%3C%2FSPAN%3E%3CSPAN%3E%20testField%20%3D%20SyslogMessage%20%2F%2F%20here%20it%20fails%20to%20call%20SyslogMessage%2C%20even%20if%20SyslogMessage%20is%20passed%20as%20a%20strandalone%20string%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F%2F%20PART3%3A%20invoke%20the%20function%20and%20pass%20the%20filtered%20dataset%20as%20parameter%3C%2FSPAN%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3EparserFunc(filteredDataSet)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ENote%20that%20the%20function%20seems%20to%20be%20able%20to%20read%20the%20passed%20table%20as%20a%20whole%2C%20but%20not%20to%20invoke%20a%20specific%20column%20from%20the%20table.%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EThis%20func%20returns%20the%20filtered%20dataset%20properly%3A%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3Elet%20parserFunc%20%3D%20(T%3C%2FSPAN%3E%3CSPAN%3E%3A%3C%2FSPAN%3E%3CSPAN%3E(*)%20)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ET%20%3C%2FSPAN%3E%3CSPAN%3E%2F%2F%7C%20extend%20testField%20%3D%20SyslogMessage%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1567185%22%20slang%3D%22en-US%22%3ERe%3A%20KQL%20Performance%20Optimization%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1567185%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F540154%22%20target%3D%22_blank%22%3E%40majo01%3C%2FA%3E%26nbsp%3B%3A%20the%20function%20needs%20to%20be%20defined%20with%20parameters%20for%20the%20fields%20that%20you%20will%20reference%3B%20the%20table%20you%20pass%20in%20will%20require%20those%20fields%20but%20can%20have%20others.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

 

Hello folks,

I am building  query that basically does the following :

 

1-  Extend and Project fields from Table1, which contains syslogs

2- Summarize table fields mentioned in (1)

3- Join the summarized table with a static datatable (Table2)

 

The performance is poor, it frequently hits the 10 minutes limits. I did troubleshooting by isolation; decomposing the query into sub-queries to pinpoint the problematic part, and found it's the summarize line!

 

Acting on the same dataset: Extend/Project operations take few seconds, JOIN takes few seconds, Summarize hits the 10 mins limit

 

QUESTION1: What are the options to improve the performance of the Summarize operation? I tried hint.strategy=shuffle but it didn't change the situation.

 

QUESTION2: How to review/confirm the settings of Data Partitioning Policy and Shuffle strategy  in Sentinel ?

 

Tried both lines:

| summarize  count() by app;

| summarize hint.strategy=shuffle count() by app;
 

 

13 Replies
Highlighted

@majo01 

 

I suspect you have read this: https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/best-practices

 

Is the summarize that's having the issue within the Join or outside the join?  If the data is Syslog, I assume its the Syslog table and you have that on the right of the join - see link above  (the datatable being the smaller table on the left?).  Are you able to reduce the data from syslog, maybe use a bin if its across many hours or days?


Can you offer a sample of the datatable and Syslog syntax?  

 

 

 

Highlighted

@Clive Watson 

Yes, i read it.

Summarize is outside the JOIN, and  i confirmed that it's the culprit, not the JOIN. Any ideas to improve the performance of JOIN, given that the dataset it's acting on it very huge (tens of millions of logs).

 

//PART1: Logs preparation, note that syslog1 is a function created elsewhere:

Syslog1

| where TimeGenerated > startDatetime and TimeGenerated < endDatetime
| where Activity == "TRAFFIC" or Activity == "THREAT"

| project-rename signature = ThreatName
| project-rename threat_category = ThreatCategory
| project-rename category= ThreatType, severity = SeverityLevel, action = DeviceAction, content_version = ContentVersion

| extend app = tostring(Application), day = dayofmonth(TimeGenerated), month = getmonth(TimeGenerated), year = getyear(TimeGenerated)
| extend traffic = toint(Bytes)
| extend parsed_src_IP = parse_ipv4(SourceIP)
| extend src_zone = case(parsed_src_IP between ( parse_ipv4("192.168.0.0") .. parse_ipv4("192.168.255") ),"Guest",
parsed_src_IP between ( parse_ipv4("127.0.0.0") .. parse_ipv4("127.0.0.1") ),"Corporate",
parsed_src_IP between ( parse_ipv4("10.0.0.0") .. parse_ipv4("10.255.255.255") ),"Corporate",
parsed_src_IP between ( parse_ipv4("172.16.0.0") .. parse_ipv4("172.31.255.255") ),"Corporate",
//else
"Public")
| extend parsed_dst_IP = parse_ipv4(DestinationIP)
| extend dst_zone = case(parsed_dst_IP between ( parse_ipv4("192.168.0.0") .. parse_ipv4("192.168.255") ),"Guest",
parsed_dst_IP between ( parse_ipv4("127.0.0.0") .. parse_ipv4("127.0.0.1") ),"Corporate",
parsed_dst_IP between ( parse_ipv4("10.0.0.0") .. parse_ipv4("10.255.255.255") ),"Corporate",
parsed_dst_IP between ( parse_ipv4("172.16.0.0") .. parse_ipv4("172.31.255.255") ),"Corporate",
//else
"Public")

 

// Problematic Part which is the following summarize statement

| summarize sum(traffic), count(app) by app, src_zone, dst_zone

 

// PART3:

JOIN

Highlighted

@majo01 :

 

I think there is little to do with "summarize" beyond shuffle. Is the performance prior to summarize reasonable? 

 

One option is to filter before parsing. If it is easy to check Activity on raw syslog, it should accelerate things considerably. I woudl first check by including the parser in the query. If it works, the parser can be omdified to be a parameter function that can be applied after initial filtering. 

Highlighted

@Ofer_Shezaf 

 

Thank you.

 

I tried a bit to make a parser as parameter function, something is going wrong. How can we call the tabular parameter from within the function ?

 

Below is sample:

 

//PART1: prepare the filtered dataset that's to be passed to the parser

let filteredDataSet = Syslog
| where SyslogMessage contains ",TRAFFIC,";
 
//PART2: the parameterized function with tablular parameter. The function will perform Extend/Project actions on the table / message passed to it as parameter
let parserFunc = (T:(*) )
{
T | extend testField = SyslogMessage // here it fails to call SyslogMessage, even if SyslogMessage is passed as a strandalone string
};
 
// PART3: invoke the function and pass the filtered dataset as parameter
parserFunc(filteredDataSet)
 
Note that the function seems to be able to read the passed table as a whole, but not to invoke a specific column from the table.
This func returns the filtered dataset properly:
 
let parserFunc = (T:(*) )
{
T //| extend testField = SyslogMessage
};

 

Highlighted

@majo01 : the function needs to be defined with parameters for the fields that you will reference; the table you pass in will require those fields but can have others.

Highlighted

@Ofer_Shezaf 

 

So if want to reference the SyslogMessage field of the syslog table in the parameter function, should it be like this:

 

let parserFunc = (T:(*), msg:string )
{
T | extend testField = msg
};

 

Can you provide  a quick example of how the function should be built and called ?

 

Thanks in advance

 

Highlighted

@majo01,

 

here it is:

 

let parserFunc = (T:(SyslogMessage:string))
{
T | extend testField = SyslogMessage
};
Syslog | invoke parserFunc ()

 

the idea is to define for T the fields that want to reference in the body of the fucntion. The other "fix" is that you need to use invokde to use functions that accept tables as input.

Highlighted

@Ofer_Shezaf 

Hi Ofer,

 

I found that if i save the function Under "Saved Queries" and as a function, it won't work by calling it from KQL editor. Is this expected ?

 

The code works when all put together in same KQL window

 

Working scenario:

let parserFunc = (T:(SyslogMessage:string))
{
T | extend testField = SyslogMessage
};
Syslog | invoke parserFunc ()

Non-working scenario (required scenario):

Save the function as "testFunc":

let parserFunc = (T:(SyslogMessage:string))
{
T | extend testField = SyslogMessage
};

 

Then invoke the function from KQL:

Syslog | invoke testFunc ()

 

The result is "Body of the callable expression cannot be empty" .

The requirement is that to save the paramter function so that it gets reused and invoked by many users

 

Highlighted

ahh, this is the exact same problem as in Kusto user-defined function for common actions 

Highlighted

@majo01 : at this time, saving and updating parameter queries needs to be done using the API, or more conveniently, PowerShell. This works, but is not visible in the query explorer.

Highlighted
Could you share the join part of the query?
If your left table is bigger than the right table, it is recommended to use lookup operator for the performance. https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/lookupoperator

Apart from that, what happens if you try the following?
staticTable
| join (
syslogData | extend columns
) on common columns
| summarize
Highlighted

@Ofer_Shezaf just tried this with a minimal example below and I'm still seeing the same error "Body of the callable expression cannot be empty". I can confirm as expected the query doesn't show up in the query explorer if I use the functionalias and and functionparameter args, but see it's registered as when I remove it I get "Unknown function: 'is_primary'."

 

$ResourceGroupName = "my_rg"
$WorkspaceName = "my_workspace"
$Version = 1
$DisplayName = "is_primary_fx"
$SavedSearchId = "$DisplayName"
$Category = "lookupfx"
$FunctionAlias = "is_primary"
$FunctionParameter = 'ip:string'
$query = @"
let is_primary = (ip:string) {
    iif(dynamic([
        "127.0.0.1",
        "127.0.0.2",
        "127.0.0.3"
    ]) contains ip, true, false)
};
"@

New-AzOperationalInsightsSavedSearch `
    -ResourceGroupName $ResourceGroupName `
    -WorkspaceName $WorkspaceName `
    -DisplayName $DisplayName `
    -Category $Category `
    -SavedSearchId $SavedSearchId `
    -Query $query `
    -Version $Version `
    -FunctionAlias $FunctionAlias `
    -FunctionParameter $FunctionParameter 

 

Attempted to test with:

// Basic print, expect true
print is_primary("127.0.0.1")

// Filter a datatable
let NetworkData = datatable (Address:string )
[
"127.0.0.1",
"127.1.1.1",
"127.0.0.2",
"127.2.2.2"
];
NetworkData
| where is_primary(Address)

 

Highlighted

@pemontto as you do for non-parameter functions when you save them in the workspace, the fucntion has to be a valid query, not a let statement. The parameter definition and alias are part of the API/PS and not needed in a let statement. Here is an example:

 

Set-AzContext -Subscription "...." -Name 'MyContext'
New-AzOperationalInsightsSavedSearch `
-ResourceGroupName "soc" `
-WorkspaceName "..." `
-SavedSearchId "is_private_addr_id" `
-DisplayName "is_private_addr" `
-Category "Advanced Functions" `
-Query "ipv4_is_match(ipaddr, '192.168.0.0/16') or ipv4_is_match(ipaddr, '172.16.0.0/12') or ipv4_is_match(ipaddr, '10.0.0.0/8')" `
-FunctionAlias "is_private_addr" `
-FunctionParameter "ipaddr: string" `
-Version 1 `
-Force