The bottom code is what I am using to query log analytics. All I am getting are results with the column names only, but no actual data. I have already logged in to my azure using the CLI. Have set up the right workspace ID as well. Do I have to enable anything else? The same query runs properly when I run it directly in the azure portal of log analytics. My end goal is to query logs of a kubernet service running.
import { Durations, LogsQueryClient, LogsQueryResultStatus, LogsTable } from "@azure/monitor-query";
const azureLogAnalyticsWorkspaceId = "xxx";
const logsQueryClient = new LogsQueryClient(new DefaultAzureCredential());
export const queryLogAnalytics = async () => {
const kustoQuery = `KubePodInventory`;
const result = await logsQueryClient.queryWorkspace(azureLogAnalyticsWorkspaceId, kustoQuery, {
duration: Durations.twentyFourHours,
});
console.log(result);
if (result.status === LogsQueryResultStatus.Success) {
const tablesFromResult: LogsTable[] = result.tables;
if (tablesFromResult.length === 0) {
console.log(`No results for query '${kustoQuery}'`);
return;
}
console.log(`This query has returned table(s) - `);
processTables(tablesFromResult);
} else {
console.log(`Error processing the query '${kustoQuery}' - ${result.partialError}`);
if (result.partialTables.length > 0) {
console.log(`This query has also returned partial data in the following table(s) - `);
processTables(result.partialTables);
}
}
}
This is the result I get when I run the code.
{
tables: [
{
name: 'PrimaryResult',
columns: [Array],
rows: [],
columnDescriptors: [Array]
}
],
statistics: undefined,
visualization: undefined,
status: 'Success'
}
This query has returned table(s) -
| TenantId(string) | SourceSystem(string) | TimeGenerated(datetime) | Computer(string) | ClusterId(string) | ContainerCreationTimeStamp(datetime) | PodUid(string) | PodCreationTimeStamp(datetime) | InstanceName(string) | ContainerRestartCount(int) | PodRestartCount(int) | PodStartTime(datetime) | ContainerStartTime(datetime) | ServiceName(string) | ControllerKind(string) | ControllerName(string) | ContainerStatus(string) | ContainerID(string) | ContainerName(string) | Name(string) | PodLabel(string) | Namespace(string) | PodStatus(string) | ClusterName(string) | PodIp(string) | ContainerStatusReason(string) | ContainerLastStatus(string) | Type(string) | _ResourceId(string)