Skip to content

Commit

Permalink
fix(refine-log-filtering) Filter out specific logs #WPB-11179 (#23)
Browse files Browse the repository at this point in the history
* fix(refine-log-filtering) Filter out specific logs
* Remove redundant "text" keyword in logger filtering
* Update github-action ci step to v1

---------

Co-authored-by: Marco <[email protected]>
  • Loading branch information
spoonman01 and marcoconti83 authored Oct 4, 2024
1 parent d751746 commit e15e3c2
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 41 deletions.
24 changes: 16 additions & 8 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,26 @@ jobs:
# delete bakup file
rm "$SERVICE.yaml.bak"
# Setup gcloud CLI
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0
- name: Enable auth plugin
run: |
echo "USE_GKE_GCLOUD_AUTH_PLUGIN=True" >> $GITHUB_ENV
# Auth to GKE
- name: Authenticate to GKE
uses: google-github-actions/auth@v1
with:
service_account_email: [email protected]
service_account_key: ${{ secrets.GKE_SA_KEY }}
project_id: wire-bot
export_default_credentials: true
credentials_json: ${{ secrets.GKE_SA_KEY }}
service_account: [email protected]

# Setup gcloud CLI
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1

# Configure Docker to use the gcloud command-line tool
- name: Configure Docker Google cloud
# Prepare components
- name: Prepare gcloud components
run: |
gcloud components install gke-gcloud-auth-plugin
gcloud components update
gcloud --quiet auth configure-docker
# Get the GKE credentials so we can deploy to the cluster
Expand Down
24 changes: 16 additions & 8 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,26 @@ jobs:
build-args: |
release_version=${{ env.RELEASE_VERSION }}
# Setup gcloud CLI
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0
- name: Enable auth plugin
run: |
echo "USE_GKE_GCLOUD_AUTH_PLUGIN=True" >> $GITHUB_ENV
# Auth to GKE
- name: Authenticate to GKE
uses: google-github-actions/auth@v1
with:
service_account_email: [email protected]
service_account_key: ${{ secrets.GKE_SA_KEY }}
project_id: wire-bot
export_default_credentials: true
credentials_json: ${{ secrets.GKE_SA_KEY }}
service_account: [email protected]

# Setup gcloud CLI
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1

# Configure Docker to use the gcloud command-line tool
- name: Configure Docker Google cloud
# Prepare components
- name: Prepare gcloud components
run: |
gcloud components install gke-gcloud-auth-plugin
gcloud components update
gcloud --quiet auth configure-docker
# Get the GKE credentials so we can deploy to the cluster
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
kotlin("jvm") version "1.5.30"
application
distribution
id("net.nemerosa.versioning") version "2.14.0"
id("net.nemerosa.versioning") version "3.1.0"
}

group = "com.wire.bots.polls"
Expand Down
21 changes: 19 additions & 2 deletions src/main/kotlin/com/wire/bots/polls/dto/roman/Message.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,17 @@ data class Message(
* Type of the file
*/
val mimeType: String?,

) {
data class Text(
val data: String,
val mentions: List<Mention>?
)

) {
override fun toString(): String {
return "Text(mentions=$mentions)"
}
}

/**
* Poll representation for the proxy.
Expand All @@ -97,7 +103,18 @@ data class Message(
* Id of the button when it was clicked on.
*/
val offset: Int?
)
) {
override fun toString(): String {
return "PollObjectMessage(id='$id', buttons=$buttons, offset=$offset)"
}
}

/**
* Avoid printing out the token by mistake if object is printed.
*/
override fun toString(): String {
return "Message(botId='$botId', userId=$userId, conversationId=$conversationId, type='$type', messageId=$messageId, text=$text, refMessageId=$refMessageId, reaction=$reaction, image=$image, handle=$handle, locale=$locale, poll=$poll, mimeType=$mimeType)"
}
}

/* JSON from the swagger
Expand Down
36 changes: 14 additions & 22 deletions src/main/kotlin/com/wire/bots/polls/setup/HttpClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@ package com.wire.bots.polls.setup
import com.wire.bots.polls.utils.ClientRequestMetric
import com.wire.bots.polls.utils.createLogger
import com.wire.bots.polls.utils.httpCall
import io.ktor.client.HttpClient
import io.ktor.client.engine.apache.Apache
import io.ktor.client.features.json.JacksonSerializer
import io.ktor.client.features.json.JsonFeature
import io.ktor.client.features.logging.LogLevel
import io.ktor.client.features.logging.Logger
import io.ktor.client.features.logging.Logging
import io.ktor.client.*
import io.ktor.client.engine.apache.*
import io.ktor.client.features.json.*
import io.ktor.client.features.logging.*
import io.micrometer.core.instrument.MeterRegistry


/**
* Prepares HTTP Client.
*/
fun createHttpClient(meterRegistry: MeterRegistry) =
HttpClient(Apache) {
install(JsonFeature) {
Expand All @@ -32,23 +25,22 @@ fun createHttpClient(meterRegistry: MeterRegistry) =
}
}

/**
* Debug logger for HTTP Requests.
*/
private val Logger.Companion.DEBUG: Logger
get() = object : Logger, org.slf4j.Logger by createLogger("DebugHttpClient") {
override fun log(message: String) {
debug(message)
}
}


/**
* Trace logger for HTTP Requests.
*
* Logs request/response bodies, params and headers.
* Avoids logging lines containing sensitive data
*/
private val Logger.Companion.TRACE: Logger
get() = object : Logger, org.slf4j.Logger by createLogger("TraceHttpClient") {
override fun log(message: String) {
for (blockedWord in blockedWordList) {
if (message.contains(blockedWord, ignoreCase = true)) {
return
}
}
trace(message)
}
}

private val blockedWordList = listOf("Authorization", "token", "Bearer")
1 change: 1 addition & 0 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

<logger name="org.eclipse.jetty" level="INFO"/>
<logger name="io.netty" level="INFO"/>
<logger name="org.jetbrains.exposed" level="INFO"/>

<logger name="com.wire" level="TRACE"/>

Expand Down

0 comments on commit e15e3c2

Please sign in to comment.