Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add files for saving service api logs into files #169

Merged
merged 7 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ jobs:
overwrite: false
- name: backend
verification_path: actuator/health
parameters:
-p RESULTS_ENV_OPENSEARCH=test
- name: frontend
parameters:
-p VITE_USER_POOLS_WEB_CLIENT_ID=${{ vars.VITE_USER_POOLS_WEB_CLIENT_ID }}
Expand Down Expand Up @@ -129,6 +131,8 @@ jobs:
overwrite: false
- name: backend
verification_path: actuator/health
parameters:
-p RESULTS_ENV_OPENSEARCH=production
- name: frontend
parameters:
-p VITE_USER_POOLS_WEB_CLIENT_ID=${{ vars.VITE_USER_POOLS_WEB_CLIENT_ID }}
Expand Down
13 changes: 13 additions & 0 deletions backend/openshift.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ parameters:
- name: DB_POOL_MAX_LIFETIME
description: Maximum lifetime of a connection in the pool.
value: "1800000"
- name: RESULTS_ENV_OPENSEARCH
description: Environment name for OpenSearch. # One of: development, test, production
required: true
value: development
objects:
- apiVersion: v1
kind: ImageStream
Expand Down Expand Up @@ -93,6 +97,9 @@ objects:
- image: "${NAME}-${ZONE}-${COMPONENT}:${IMAGE_TAG}"
imagePullPolicy: Always
name: "${NAME}"
volumeMounts:
- name: ${NAME}-${ZONE}-fluentbit-logs
mountPath: /logs
env:
- name: POSTGRES_HOST
value: ${NAME}-${ZONE}-database
Expand All @@ -117,6 +124,8 @@ objects:
value: ${DB_POOL_IDLE_TIMEOUT}
- name: DB_POOL_MAX_LIFETIME
value: ${DB_POOL_MAX_LIFETIME}
- name: RESULTS_ENV_OPENSEARCH
value: ${RESULTS_ENV_OPENSEARCH}
ports:
- containerPort: 8080
protocol: TCP
Expand Down Expand Up @@ -147,6 +156,10 @@ objects:
initialDelaySeconds: 60
periodSeconds: 30
timeoutSeconds: 5
volumes:
- name: ${NAME}-${ZONE}-fluentbit-logs
persistentVolumeClaim:
claimName: ${NAME}-${ZONE}-fluentbit-logs
- apiVersion: v1
kind: Service
metadata:
Expand Down
3 changes: 3 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@
<artifactId>lombok</artifactId>
</exclude>
</excludes>
<profiles>
<profile>dev</profile>
</profiles>
</configuration>
</plugin>

Expand Down
7 changes: 6 additions & 1 deletion backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# General application
logging.level.ca.bc.gov.restapi.results = ${LOGGING_LEVEL:INFO}
spring.application.name = results-backend-api
spring.application.name = results-api
server.error.include-message=always
server.port = ${SERVER_PORT:8080}

Expand Down Expand Up @@ -31,3 +31,8 @@ spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.defer-datasource-initialization=true
spring.sql.init.mode=always

# OpenSearch settings
nr-results-ecs-version = 8.9
nr-results-backend-env-opensearch = ${RESULTS_ENV_OPENSEARCH:development}
nr-results-team-email-address = [email protected]
70 changes: 70 additions & 0 deletions backend/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOGS" value="/logs" />
<springProperty scope="context" name="serviceEnv" source="nr-results-backend-env-opensearch" />
<springProperty scope="context" name="applicationName" source="spring.application.name" />
<springProperty scope="context" name="teamEmail" source="nr-results-team-email-address" />
<springProperty scope="context" name="ecsVersion" source="nr-results-ecs-version" />

<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<!-- https://logback.qos.ch/manual/layouts.html -->
<!-- %d = 2006-10-20 14:06:49,812 or we can use like %date{yyyy-MM-dd HH:mm:ss.SSS}, or %d{ISO8601} -->
<!-- %p = level -->
<!-- %C{length} = fully qualified class name of the caller -->
<!-- %t = thread name -->
<!-- %m = message -->
<!-- %n = new line -->
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%date{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-5level) [%blue(%t)] %yellow(%c): %msg%n%throwable
</Pattern>
</layout>
</appender>

<appender name="RollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS}/results-api.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>{%nopex"labels.project":"${applicationName}","service.environment":"${serviceEnv}","@timestamp":"%date{yyyy-MM-dd HH:mm:ss.SSS}","log.level":"%p","log.logger":"%logger{36}","message":"%replace(%msg){'\"','\\"'}","ecs.version":"${ecsVersion}","event.category":"web","event.dataset":"application.log.utc","event.ingested":"diagnostic","event.kind":"event","organization.id":"${teamEmail}","organization.name":"TeamSILVA"}%n</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily and when the file reaches 10 MegaBytes -->
<fileNamePattern>${LOGS}/archived/results-api-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>

<springProfile name="dev,all-tests,integration-test,test">
<!-- LOG everything at INFO level -->
<root level="info">
<appender-ref ref="Console" />
</root>
<!-- LOG "ca.bc.gov.restapi.results*" at TRACE level -->
<logger name="ca.bc.gov.restapi.results" level="trace" additivity="false">
<appender-ref ref="Console" />
</logger>
</springProfile>

<springProfile name="default,prod,native">
<!-- LOG everything at INFO level -->
<root level="info">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>
<root level="warn">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>
<root level="error">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>
<!-- LOG "ca.bc.gov.restapi.results*" at TRACE level -->
<logger name="ca.bc.gov.restapi.results" level="trace" additivity="false">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</logger>
</springProfile>

</configuration>
Loading