feat: add analytics-service (Spring Cloud Gateway + Consul)
This commit is contained in:
16
analytics-service/src/main/resources/application-prod.yml
Normal file
16
analytics-service/src/main/resources/application-prod.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:postgresql://${DB_HOST:postgres}:${DB_PORT:5432}/${DB_NAME:appdb}?currentSchema=analytics
|
||||
|
||||
kafka:
|
||||
bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS:kafka:9092}
|
||||
|
||||
cloud:
|
||||
consul:
|
||||
host: ${CONSUL_HOST:consul}
|
||||
port: ${CONSUL_PORT:8500}
|
||||
|
||||
logging:
|
||||
level:
|
||||
root: WARN
|
||||
com.posthub.analytics: INFO
|
||||
62
analytics-service/src/main/resources/application.yml
Normal file
62
analytics-service/src/main/resources/application.yml
Normal file
@@ -0,0 +1,62 @@
|
||||
server:
|
||||
port: 8082
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: analytics-service
|
||||
|
||||
datasource:
|
||||
url: jdbc:postgresql://${DB_HOST:localhost}:${DB_PORT:5432}/${DB_NAME:appdb}?currentSchema=analytics
|
||||
username: ${DB_USERNAME:app}
|
||||
password: ${DB_PASSWORD:}
|
||||
hikari:
|
||||
maximum-pool-size: 5
|
||||
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: validate
|
||||
properties:
|
||||
hibernate:
|
||||
default_schema: analytics
|
||||
open-in-view: false
|
||||
|
||||
flyway:
|
||||
enabled: true
|
||||
schemas: analytics
|
||||
default-schema: analytics
|
||||
|
||||
kafka:
|
||||
bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS:localhost:9092}
|
||||
consumer:
|
||||
group-id: analytics-group
|
||||
auto-offset-reset: earliest
|
||||
|
||||
cloud:
|
||||
consul:
|
||||
host: ${CONSUL_HOST:localhost}
|
||||
port: ${CONSUL_PORT:8500}
|
||||
discovery:
|
||||
register: true
|
||||
enabled: true
|
||||
health-check-path: /actuator/health
|
||||
health-check-interval: 15s
|
||||
prefer-ip-address: true
|
||||
instance-id: ${spring.application.name}:${random.value}
|
||||
|
||||
analytics:
|
||||
kafka:
|
||||
topic: user-events
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health,info
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always
|
||||
|
||||
logging:
|
||||
level:
|
||||
root: INFO
|
||||
com.posthub.analytics: DEBUG
|
||||
@@ -0,0 +1,38 @@
|
||||
CREATE TABLE event_log (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
event_type VARCHAR(50) NOT NULL,
|
||||
user_id VARCHAR(255) NOT NULL,
|
||||
chat_id VARCHAR(255),
|
||||
tokens_used INTEGER,
|
||||
documents_found INTEGER,
|
||||
event_timestamp TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
event_date DATE NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX idx_event_log_type ON event_log(event_type);
|
||||
CREATE INDEX idx_event_log_user ON event_log(user_id);
|
||||
CREATE INDEX idx_event_log_date ON event_log(event_date);
|
||||
|
||||
CREATE TABLE daily_stats (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
stats_date DATE NOT NULL UNIQUE,
|
||||
total_queries BIGINT DEFAULT 0,
|
||||
total_tokens_used BIGINT DEFAULT 0,
|
||||
total_rag_hits BIGINT DEFAULT 0,
|
||||
total_documents_found BIGINT DEFAULT 0,
|
||||
new_users BIGINT DEFAULT 0,
|
||||
new_chats BIGINT DEFAULT 0,
|
||||
deleted_chats BIGINT DEFAULT 0,
|
||||
active_users INTEGER DEFAULT 0
|
||||
);
|
||||
|
||||
CREATE TABLE user_stats (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
user_id VARCHAR(255) NOT NULL UNIQUE,
|
||||
total_queries BIGINT DEFAULT 0,
|
||||
total_tokens_used BIGINT DEFAULT 0,
|
||||
total_rag_hits BIGINT DEFAULT 0,
|
||||
total_chats INTEGER DEFAULT 0,
|
||||
first_seen TIMESTAMP WITH TIME ZONE,
|
||||
last_active TIMESTAMP WITH TIME ZONE
|
||||
);
|
||||
14
analytics-service/src/main/resources/logback.xml
Normal file
14
analytics-service/src/main/resources/logback.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<property name="LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"/>
|
||||
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${LOG_PATTERN}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</root>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user