Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/check-deployed-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Check deployed package

on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
check-deployed-package:
name: Check deployed package
runs-on: ubuntu-latest
permissions:
contents: read
packages: read

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Make run script executable
run: chmod +x check-deployed-package/run.sh

- name: Verify environment variables
run: |
echo "GITHUB_ACTOR: ${{ github.actor }}"
echo "Has GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN != '' }}"
echo "Has LOGDASH_API_KEY: ${{ secrets.LOGDASH_API_KEY != '' }}"

- name: Run LogDash demo
env:
LOGDASH_API_KEY: ${{ secrets.LOGDASH_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_ACTOR: ${{ github.actor }}
run: ./check-deployed-package/run.sh
58 changes: 58 additions & 0 deletions check-deployed-package/Check.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.logdash.check;

import io.logdash.sdk.Logdash;

import java.util.Map;

public class Check {
public static void main(String[] args) {
System.out.println("=== LogDash Java SDK Demo ===");

// Get package version (would need to be handled differently in a real scenario)
System.out.println("Using logdash package version: " + getLogdashVersion());
System.out.println();

String apiKey = System.getenv("LOGDASH_API_KEY");
String logsSeed = System.getenv().getOrDefault("LOGS_SEED", "default");
String metricsSeed = System.getenv().getOrDefault("METRICS_SEED", "1");

System.out.println("Using API Key: " + apiKey);
System.out.println("Using Logs Seed: " + logsSeed);
System.out.println("Using Metrics Seed: " + metricsSeed);

try (Logdash logdash = Logdash.create(apiKey)) {
var logger = logdash.logger();
var metrics = logdash.metrics();

// Log some messages with seed appended
logger.info("This is an info log " + logsSeed);
logger.error("This is an error log " + logsSeed);
logger.warn("This is a warning log " + logsSeed);
logger.debug("This is a debug log " + logsSeed);
logger.http("This is a http log " + logsSeed);
logger.silly("This is a silly log " + logsSeed);
logger.info("This is an info log " + logsSeed);
logger.verbose("This is a verbose log " + logsSeed);

// Set and mutate metrics with seed
int seedValue = Integer.parseInt(metricsSeed);
metrics.set("users", seedValue);
metrics.mutate("users", 1);

// Wait to ensure data is sent
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}

private static String getLogdashVersion() {
try {
return Check.class.getPackage().getImplementationVersion();
} catch (Exception e) {
return "unknown";
}
}
}
37 changes: 37 additions & 0 deletions check-deployed-package/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM eclipse-temurin:17-jdk

ARG GITHUB_TOKEN
ARG GITHUB_ACTOR

WORKDIR /app

# Install Maven
RUN apt-get update && apt-get install -y maven && rm -rf /var/lib/apt/lists/*

# Set environment variables for Maven authentication
ENV GITHUB_TOKEN=${GITHUB_TOKEN}
ENV GITHUB_ACTOR=${GITHUB_ACTOR}

# Copy Maven settings with GitHub authentication
COPY check-deployed-package/settings.xml /root/.m2/settings.xml

# Copy project files
COPY check-deployed-package/pom.xml .
COPY check-deployed-package/Check.java src/main/java/com/logdash/check/Check.java

# Download dependencies and compile
RUN mvn dependency:resolve compile -B --no-transfer-progress \
-Dgithub.username=${GITHUB_ACTOR} \
-Dgithub.password=${GITHUB_TOKEN}

# Add environment variable validation
ENV LOGDASH_API_KEY=""
ENV LOGS_SEED=""
ENV METRICS_SEED=""

# Run the application with environment validation
CMD if [ -z "$LOGDASH_API_KEY" ]; then \
echo "Error: LOGDASH_API_KEY environment variable is required"; \
exit 1; \
fi; \
mvn exec:java -B --no-transfer-progress
8 changes: 8 additions & 0 deletions check-deployed-package/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# LogDash Java SDK Demo

Use command below to test if the published SDK works:

```
LOGDASH_API_KEY=<your-api-key> ./check-deployed-package/run.sh
```

61 changes: 61 additions & 0 deletions check-deployed-package/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.logdash</groupId>
<artifactId>check</artifactId>
<version>1.0.0</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>io.logdash</groupId>
<artifactId>logdash</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>

<repositories>
<repository>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/logdash-io/java-sdk</url>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<mainClass>com.logdash.check.Check</mainClass>
<options>
<option>-Dfile.encoding=UTF-8</option>
</options>
</configuration>
</plugin>
</plugins>
</build>
</project>
128 changes: 128 additions & 0 deletions check-deployed-package/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/bin/sh
set -e

# Generate random 5-character seed
LOGS_SEED=$(openssl rand -hex 2 | cut -c1-5)
echo "Generated seed: $LOGS_SEED"

# Generate random metrics seed (1-1,000,000)
METRICS_SEED=$(awk 'BEGIN{srand(); print int(rand()*1000000)+1}')
echo "Generated metrics seed: $METRICS_SEED"

echo "Building LogDash Java demo Docker image (using published package)..."
docker build --no-cache \
--build-arg GITHUB_TOKEN="${GITHUB_TOKEN}" \
--build-arg GITHUB_ACTOR="${GITHUB_ACTOR}" \
-t logdash-java-demo \
-f check-deployed-package/Dockerfile .

echo
echo "Running LogDash Java demo..."
echo

# Run in non-interactive mode which works everywhere
docker run --rm \
-e LOGDASH_API_KEY="${LOGDASH_API_KEY}" \
-e LOGS_SEED="${LOGS_SEED}" \
-e METRICS_SEED="${METRICS_SEED}" \
logdash-java-demo

echo
echo "Demo completed!"

echo
echo "Authenticating with LogDash API..."

# Authenticate with API using the API key
AUTH_RESPONSE=$(curl -s -X 'POST' \
'https://api.logdash.io/auth/api-key' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d "{
\"apiKey\": \"${LOGDASH_API_KEY}\"
}")

# Extract token and projectId from response
TOKEN=$(echo "$AUTH_RESPONSE" | grep -o '"token":"[^"]*"' | sed 's/"token":"\(.*\)"/\1/')
PROJECT_ID=$(echo "$AUTH_RESPONSE" | grep -o '"projectId":"[^"]*"' | sed 's/"projectId":"\(.*\)"/\1/')

if [ -z "$TOKEN" ] || [ -z "$PROJECT_ID" ]; then
echo "Error: Failed to authenticate with LogDash API"
echo "Response: $AUTH_RESPONSE"
exit 1
fi

echo "Authentication successful. Project ID: $PROJECT_ID"

echo
echo "Fetching logs from LogDash API..."

# Fetch logs from the API
LOGS_RESPONSE=$(curl -s -X 'GET' \
"https://api.logdash.io/projects/${PROJECT_ID}/logs?limit=10" \
-H 'accept: application/json' \
-H "Authorization: Bearer ${TOKEN}")

echo "Logs fetched successfully"

echo
echo "Validating log messages..."

# Expected log messages with seed
EXPECTED_MESSAGES="This is an info log ${LOGS_SEED}
This is an error log ${LOGS_SEED}
This is a warning log ${LOGS_SEED}
This is a debug log ${LOGS_SEED}
This is a http log ${LOGS_SEED}
This is a silly log ${LOGS_SEED}
This is an info log ${LOGS_SEED}
This is a verbose log ${LOGS_SEED}"

# Check if all expected messages are present in the logs
echo "$EXPECTED_MESSAGES" | while IFS= read -r expected_msg; do
if ! echo "$LOGS_RESPONSE" | grep -q "$expected_msg"; then
echo "Error: Expected log message not found: '$expected_msg'"
echo "Logs response: $LOGS_RESPONSE"
exit 1
fi
echo "✓ Found: '$expected_msg'"
done

echo
echo "Fetching metrics from LogDash API..."

# Fetch metrics from the API
METRICS_RESPONSE=$(curl -s -X 'GET' \
"https://api.logdash.io/projects/${PROJECT_ID}/metrics" \
-H 'accept: application/json' \
-H "Authorization: Bearer ${TOKEN}")

echo "Metrics fetched successfully"

echo
echo "Validating metrics..."

# Expected users metric value (metrics_seed + 1)
EXPECTED_USERS_VALUE=$((METRICS_SEED + 1))

# Check if users metric exists with correct value
if ! echo "$METRICS_RESPONSE" | grep -q '"name":"users"'; then
echo "Error: Users metric not found"
echo "Metrics response: $METRICS_RESPONSE"
exit 1
fi

# Extract the value of the users metric and check if it matches expected value
USERS_VALUE=$(echo "$METRICS_RESPONSE" | sed 's/},{/}\n{/g' | grep '"name":"users"' | grep -o '"value":[0-9]*' | sed 's/"value"://')

if [ "$USERS_VALUE" != "$EXPECTED_USERS_VALUE" ]; then
echo "Error: Users metric value mismatch. Expected: $EXPECTED_USERS_VALUE, Found: $USERS_VALUE"
echo "Metrics response: $METRICS_RESPONSE"
exit 1
fi

echo "✓ Found users metric with correct value: $USERS_VALUE"

echo
echo "All expected log messages and metrics found successfully!"
echo "Validation completed!"
42 changes: 42 additions & 0 deletions check-deployed-package/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">

<servers>
<server>
<id>github</id>
<username>${env.GITHUB_ACTOR}</username>
<password>${env.GITHUB_TOKEN}</password>
</server>
</servers>

<profiles>
<profile>
<id>github-auth</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/logdash-io/java-sdk</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>

<activeProfiles>
<activeProfile>github-auth</activeProfile>
</activeProfiles>
</settings>
Loading