Skip to content

Latest commit

 

History

History

lab

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Lab

A test and demonstration tool for generating and exploring logs in both formatted and JSON styles, integrated with Grafana Loki via Docker.

npm version size ossf scorecard license

🚧 Requirements

🚀 Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn

$ npm i @sigyn/lab
# or
$ yarn add @sigyn/lab

📚 Usage

import { run } from "@sigyn/lab";

await run({
  count: 200,
  labels: {
    app: "demo-app"
  }
});
// Grafana Loki ready on http://localhost:3000 with 200 random logs.

🌐 API

run(options?: LogGeneratorOptions): Promise<void>

Run Grafana + Loki via Docker (using testcontainers) with multiple logs.

See LogGenerator for options.

Default options:

{
  count: 500,
  labels: { app: "demo" }
}

LogGenerator

The LogGenerator class is responsible for generating logs in two different styles: formatted strings and JSON objects. These logs are designed for testing, demonstrations, and integration with Grafana Loki.

new LogGenerator(options: LogGeneratorOptions)

Constructor parameters

options (optional): An object to customize log generation:

  • options.mode (optional): Specifies the style of the logs. Can be:
    • "formated": Generates logs as formatted strings.
    • "json": G**enerates logs as JSON objects.
    • "random" (default): Randomly chooses between "formated" and "json" for each log.
  • options.count (optional): The number of logs to generate. Default is 100.
  • options.labels (optional): An object containing custom labels to associate with each log stream. No labels by default.
  • options.startUnixEpoch (optional): The start timestamp for logs in nanoseconds. Default is one hour before the current time.
  • options.endUnixEpoch (optional): The end timestamp for logs in nanoseconds. Default is the current time.

LogGenerator.generate()

Generates logs based on the provided options. This method is a generator function that yields individual log entries.

Example usage:

const generator = new LogGenerator({
  count: 10,
  mode: "json"
});
const logs = [...generator.generate()];

console.log(logs);

🖋️ Interfaces

interface LogGeneratorOptions {
  mode?: Mode;
  count?: number;
  labels?: Record<string, string>;
  startUnixEpoch?: number;
  endUnixEpoch?: number;
}

License

MIT