removed logs folder

This commit is contained in:
yaowenc2
2025-10-01 14:59:06 -07:00
parent eb60e5faac
commit dc953b7a3f
5 changed files with 25 additions and 83 deletions
@@ -10,6 +10,8 @@ import {
import { LogSource, AnalyticsLogRecord, LogSourceStats } from '@/types/logs.js';
import logger from '@/utils/logger.js';
import { BaseAnalyticsProvider } from './base.provider.js';
import { AppError } from '@/api/middleware/error.js';
import { ERROR_CODES } from '@/types/error-constants.js';
export class CloudWatchProvider extends BaseAnalyticsProvider {
private cwClient: CloudWatchLogsClient | null = null;
@@ -57,7 +59,11 @@ export class CloudWatchProvider extends BaseAnalyticsProvider {
async getLogSources(): Promise<LogSource[]> {
if (!this.cwLogGroup || !this.cwClient) {
throw new Error('CloudWatch not initialized');
throw new AppError(
'AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY not found in environment variables',
500,
ERROR_CODES.LOGS_AWS_NOT_CONFIGURED
);
}
const logGroup = this.cwLogGroup;
const client = this.cwClient;
@@ -90,7 +96,11 @@ export class CloudWatchProvider extends BaseAnalyticsProvider {
tableName: string;
}> {
if (!this.cwLogGroup || !this.cwClient) {
throw new Error('CloudWatch not initialized');
throw new AppError(
'AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY not found in environment variables',
500,
ERROR_CODES.LOGS_AWS_NOT_CONFIGURED
);
}
const client = this.cwClient;
const logGroup = this.cwLogGroup;
@@ -278,7 +288,11 @@ export class CloudWatchProvider extends BaseAnalyticsProvider {
async getLogSourceStats(): Promise<LogSourceStats[]> {
if (!this.cwLogGroup || !this.cwClient) {
throw new Error('CloudWatch not initialized');
throw new AppError(
'AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY not found in environment variables',
500,
ERROR_CODES.LOGS_AWS_NOT_CONFIGURED
);
}
const client = this.cwClient;
const logGroup = this.cwLogGroup;
@@ -338,7 +352,11 @@ export class CloudWatchProvider extends BaseAnalyticsProvider {
total: number;
}> {
if (!this.cwLogGroup || !this.cwClient) {
throw new Error('CloudWatch not initialized');
throw new AppError(
'AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY not found in environment variables',
500,
ERROR_CODES.LOGS_AWS_NOT_CONFIGURED
);
}
const client = this.cwClient;
const logGroup = this.cwLogGroup;
+3
View File
@@ -39,6 +39,9 @@ export enum ERROR_CODES {
// AI module
AI_INVALID_API_KEY = 'AI_INVALID_API_KEY',
// LOGS module
LOGS_AWS_NOT_CONFIGURED = 'LOGS_AWS_NOT_CONFIGURED',
// Billing module
BILLING_INSUFFICIENT_BALANCE = 'BILLING_INSUFFICIENT_BALANCE',
-1
View File
@@ -11,7 +11,6 @@ services:
- postgres-data:/var/lib/postgresql/data
- ./docker-init/db/db-init.sql:/docker-entrypoint-initdb.d/01-init.sql
- ./docker-init/db/jwt.sql:/docker-entrypoint-initdb.d/02-jwt.sql
- ./docker-init/db/logs.sql:/docker-entrypoint-initdb.d/03-logs.sql
- ./docker-init/db/postgresql.conf:/etc/postgresql/postgresql.conf
ports:
- "5432:5432"
-1
View File
@@ -13,7 +13,6 @@ services:
- postgres-data:/var/lib/postgresql/data
- ./docker-init/db/db-init.sql:/docker-entrypoint-initdb.d/01-init.sql
- ./docker-init/db/jwt.sql:/docker-entrypoint-initdb.d/02-jwt.sql
- ./docker-init/db/logs.sql:/docker-entrypoint-initdb.d/03-logs.sql
- ./docker-init/db/postgresql.conf:/etc/postgresql/postgresql.conf
ports:
- "5432:5432"
-77
View File
@@ -1,77 +0,0 @@
\set pguser `echo "$POSTGRES_USER"`
CREATE DATABASE _insforge WITH OWNER :pguser;
\c _insforge
create schema if not exists _analytics;
alter schema _analytics owner to :pguser;
-- Create sources table to track different log sources
CREATE TABLE IF NOT EXISTS _analytics.sources (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL UNIQUE,
token VARCHAR(255) NOT NULL UNIQUE,
created_at TIMESTAMP DEFAULT NOW()
);
-- Insert default log sources
INSERT INTO _analytics.sources (name, token) VALUES
('cloudflare.logs.prod', 'insforge-vector'),
('deno-relay-logs', 'function-vector'),
('postgREST.logs.prod', 'postgrest-vector'),
('postgres.logs', 'postgres-vector')
ON CONFLICT (name) DO NOTHING;
-- Create log event tables for each source
-- Vector will insert logs into these tables
CREATE TABLE IF NOT EXISTS _analytics.log_events_insforge_vector (
id VARCHAR(255) PRIMARY KEY,
event_message TEXT,
timestamp TIMESTAMP NOT NULL DEFAULT NOW(),
body JSONB,
created_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS _analytics.log_events_function_vector (
id VARCHAR(255) PRIMARY KEY,
event_message TEXT,
timestamp TIMESTAMP NOT NULL DEFAULT NOW(),
body JSONB,
created_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS _analytics.log_events_postgrest_vector (
id VARCHAR(255) PRIMARY KEY,
event_message TEXT,
timestamp TIMESTAMP NOT NULL DEFAULT NOW(),
body JSONB,
created_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS _analytics.log_events_postgres_vector (
id VARCHAR(255) PRIMARY KEY,
event_message TEXT,
timestamp TIMESTAMP NOT NULL DEFAULT NOW(),
body JSONB,
created_at TIMESTAMP DEFAULT NOW()
);
-- Create indexes for better query performance
CREATE INDEX IF NOT EXISTS idx_insforge_timestamp ON _analytics.log_events_insforge_vector(timestamp DESC);
CREATE INDEX IF NOT EXISTS idx_function_timestamp ON _analytics.log_events_function_vector(timestamp DESC);
CREATE INDEX IF NOT EXISTS idx_postgrest_timestamp ON _analytics.log_events_postgrest_vector(timestamp DESC);
CREATE INDEX IF NOT EXISTS idx_postgres_timestamp ON _analytics.log_events_postgres_vector(timestamp DESC);
-- Create indexes for search performance on event_message
CREATE INDEX IF NOT EXISTS idx_insforge_message ON _analytics.log_events_insforge_vector USING gin(to_tsvector('english', event_message));
CREATE INDEX IF NOT EXISTS idx_function_message ON _analytics.log_events_function_vector USING gin(to_tsvector('english', event_message));
CREATE INDEX IF NOT EXISTS idx_postgrest_message ON _analytics.log_events_postgrest_vector USING gin(to_tsvector('english', event_message));
CREATE INDEX IF NOT EXISTS idx_postgres_message ON _analytics.log_events_postgres_vector USING gin(to_tsvector('english', event_message));
-- Create indexes for JSONB body search
CREATE INDEX IF NOT EXISTS idx_insforge_body ON _analytics.log_events_insforge_vector USING gin(body);
CREATE INDEX IF NOT EXISTS idx_function_body ON _analytics.log_events_function_vector USING gin(body);
CREATE INDEX IF NOT EXISTS idx_postgrest_body ON _analytics.log_events_postgrest_vector USING gin(body);
CREATE INDEX IF NOT EXISTS idx_postgres_body ON _analytics.log_events_postgres_vector USING gin(body);
\c insforge