Files
openobserve/tests/ui-testing/playwright-tests/utils/dashIngestion.js
T
73b49ea686 test: dashboard filter testcases (#6284)
Co-authored-by: ktx-kirtan <124270523+ktx-kirtan@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: Kirtan Thakkar <kirtan@kiara.tech>
2025-03-17 15:13:49 +05:30

52 lines
1.5 KiB
JavaScript

// ingestion.js
import logsdata from "../../../test-data/logs_data.json"
// Exported function to remove UTF characters
export const removeUTFCharacters = (text) => {
// console.log(text, "tex");
// Remove UTF characters using regular expression
return text.replace(/[^\x00-\x7F]/g, " ");
};
// Function to retrieve authentication token (to be implemented securely)
const getAuthToken = async () => {
const basicAuthCredentials = Buffer.from(
`${process.env["ZO_ROOT_USER_EMAIL"]}:${process.env["ZO_ROOT_USER_PASSWORD"]}`
).toString("base64");
return `Basic ${basicAuthCredentials}`;
};
// page is passed here to access the page object (currently not used)
export const ingestion = async (page, streamName = "e2e_automate") => {
if (!process.env["ORGNAME"] || !process.env["INGESTION_URL"]) {
throw new Error("Required environment variables are not set");
}
const orgId = process.env["ORGNAME"];
try {
const headers = {
"Content-Type": "application/json",
Authorization: await getAuthToken(),
};
const fetchResponse = await fetch(
`${process.env.INGESTION_URL}/api/${orgId}/${streamName}/_json`,
{
method: "POST",
headers,
body: JSON.stringify(logsdata),
}
);
if (!fetchResponse.ok) {
throw new Error(`HTTP error! status: ${fetchResponse.status}, response: ${fetchResponse}`);
}
return await fetchResponse.json();
} catch (error) {
console.error("Ingestion failed:", error);
throw error;
}
};