skip to Main Content

I am having the following problem and an extensive search online didn’t provide any good results.
When trying to access my Azure Data Explorer Database and querying using the Kusto.Data SDK in an Azure Function, it yields the following error:

Kusto client failed to send a request to the service: ‘An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call.’

However, running the Function on my local machine, everything works fine.

Edit: The function excepts at using (var reader = await queryProvider.ExecuteQueryAsync(Database, query, clientRequestProperties))

EDIT2 – SOLUTION:

You can downgrade the NuGet Kusto.Data Package to Version 9.4.1, this solves the problem and doesn’t throw any error anymore. If you still encounter difficulties, you can try to directly access the ADX database via http requests:

const string tenantId = "<tenantId>";
const string client_id = "<clientId>";
const string client_secret = "<client_secret>";
const string Cluster = "<cluster_adress";
const string Database = "<database_name>";

var authUrl = "https://login.microsoftonline.com/<tenantId>/oauth2/token";
var param = new Dictionary<string, string>
            {
                {"client_id",client_id},
                {"grant_type","client_credentials"},
                {"client_secret",client_secret},
                {"resource","https://help.kusto.windows.net"}
            };
var data = new FormUrlEncodedContent(param);
using var authClient = new HttpClient();
var response = await authClient.PostAsync(authUrl, data);
string result = response.Content.ReadAsStringAsync().Result;

//parse result
var resultJson = System.Text.Json.JsonDocument.Parse(result);
//retrieve access token
var accessToken = resultJson.RootElement.GetProperty("access_token");
//-----------------------------------------------------------------------------------------------

var dataXUrl = Cluster + "/v1/rest/query";
var database = Database;

var dataXQuery = "sample_table| where Time > ago(2min)";
var body = new Dictionary<string, string>
{
    {"db",database},
    {"csl",dataXQuery}
};

using var dataXClient = new HttpClient();
dataXClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.ToString());
dataXClient.DefaultRequestHeaders.Add("Accept", "application/json");

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, dataXUrl);
request.Content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");

var table = await dataXClient.SendAsync(request);

//pretty print
var obj = JsonConvert.DeserializeObject(table.Content.ReadAsStringAsync());
var tableJSON = JsonConvert.SerializeObject(obj, Formatting.Indented);

log.LogInformation("nn" + tableJSON);

2

Answers


  1. I am having the same issue on a continuous webjob on an Azure App Service. The Kusto nuget version I am using is 10.1.0

    Downgrading to nuget 9.4.1 solved the problem immediately.

    Login or Signup to reply.
  2. FYI – This only seems to affect 10.1.0. The earlier 10.x.x versions should work.

    The ADX team believes they will have this fixed in the next nuget version.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search