Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

added grok rules and created logstack-shipper in dev #45

Merged
merged 20 commits into from
Jan 10, 2024
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
Binary file added .DS_Store
Binary file not shown.
16 changes: 14 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ jobs:
- name: drain-staging-space
uses: cloud-gov/cg-cli-tools@main
with:
command: apt-get install -y jq && cf install-plugin -f -r CF-Community "drains" && mkdir -p /root/.cf/ && touch /root/.cf/config.json && ./create-space-drain.sh
command: |
apt-get install -y jq &&
curl -L -o drain-plugin https://github.com/cloudfoundry/cf-drain-cli/releases/download/v2.0.0/cf-drain-cli-linux &&
cf install-plugin -f -r drain-plugin &&
rm -f drain-plugin &&
mkdir -p /root/.cf/ && touch /root/.cf/config.json &&
./create-space-drain.sh management-staging
cf_org: gsa-datagov
cf_space: staging
cf_username: ${{secrets.CF_SERVICE_USER}}
Expand All @@ -123,7 +129,13 @@ jobs:
- name: drain-prod-space
uses: cloud-gov/cg-cli-tools@main
with:
command: apt-get install -y jq && cf install-plugin -f -r CF-Community "drains" && mkdir -p /root/.cf/ && touch /root/.cf/config.json && ./create-space-drain.sh
command: |
apt-get install -y jq &&
curl -L -o drain-plugin https://github.com/cloudfoundry/cf-drain-cli/releases/download/v2.0.0/cf-drain-cli-linux &&
cf install-plugin -f -r drain-plugin &&
rm -f drain-plugin &&
mkdir -p /root/.cf/ && touch /root/.cf/config.json &&
./create-space-drain.sh management
cf_org: gsa-datagov
cf_space: prod
cf_username: ${{secrets.CF_SERVICE_USER}}
Expand Down
75 changes: 75 additions & 0 deletions .github/workflows/dev-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
name: dev-deploy

on:
push:
branches:
- development
workflow_dispatch:
Comment on lines +1 to +8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to setup similar things for staging and prod?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that exists above in deploy.yml, as far as I can tell. Would it be beneficial then to combine them and make environ a variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Staging and prod setup are already included in the deploy.yml file. For debug purpose we separate development out so we may test/debug any changes push to development brunch first instead of master brunch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems worthwhile to merge and road test in development. If we want to consolidate in the future, we can do so.


jobs:
create-cloudgov-services-development-ssb:
name: create services (development-ssb)
environment: development-ssb
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: create services
uses: cloud-gov/cg-cli-tools@main
with:
command: ./create-cloudgov-services.sh
cf_org: gsa-datagov
cf_space: development-ssb
cf_username: ${{secrets.CF_SERVICE_USER}}
cf_password: ${{secrets.CF_SERVICE_AUTH}}

deploy-development-ssb:
name: deploy (development-ssb)
environment: development-ssb
runs-on: ubuntu-latest
needs:
- create-cloudgov-services-development-ssb
steps:
- name: checkout
uses: actions/checkout@v2
- name: build dependencies
run: |
chmod -R 777 logstash
PWD=`pwd` make logstash-installation
- name: deploy-logstash
uses: cloud-gov/cg-cli-tools@main
with:
command: cf push --vars-file vars.development-ssb.yml --strategy rolling
cf_org: gsa-datagov
cf_space: development-ssb
cf_username: ${{secrets.CF_SERVICE_USER}}
cf_password: ${{secrets.CF_SERVICE_AUTH}}
- name: smoke test logstash
run: |
sleep 150 # Logstash is very slow to start up
[ "401" = "$(curl -w '%{http_code}' --output /dev/null --silent https://logstash-development-datagov.app.cloud.gov)" ]

drain-apps-in-development:
name: drain everything in development space
environment: development-ssb
runs-on: ubuntu-latest
needs:
- deploy-development-ssb
steps:
- name: checkout
uses: actions/checkout@v2
- name: drain-development-space
uses: cloud-gov/cg-cli-tools@main
with:
command: |
apt-get install -y jq &&
curl -L -o drain-plugin https://github.com/cloudfoundry/cf-drain-cli/releases/download/v2.0.0/cf-drain-cli-linux &&
cf install-plugin -f -r drain-plugin &&
rm -f drain-plugin &&
mkdir -p /root/.cf/ && touch /root/.cf/config.json &&
./create-space-drain.sh development-ssb
cf_org: gsa-datagov
cf_space: development
cf_username: ${{secrets.CF_SERVICE_USER}}
cf_password: ${{secrets.CF_SERVICE_AUTH}}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
logstash/logstash-oss-*-linux-x86_64.tar.gz
logstash/plugins.zip
logstash/awscliv2.zip
.DS_Store
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ Alternatively, you can auto-drain all apps in a given space by targeting that sp
cf target -s prod
./create-space-drain.sh

Note: at development space, it will use the logstack-shipper in development-ssb space:

cf target -s development
./create-space-drain.sh development-ssb

After a short delay, logs should begin to flow automatically.

## Setup
Expand Down
2 changes: 1 addition & 1 deletion create-cloudgov-services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ space=$(cf target | grep space | cut -d : -f 2 | xargs)
randpw(){ openssl rand -base64 40 | tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo; }

# Only create stuff in production and staging spaces
if [ "$space" = "management" ] || [ "$space" = "management-staging" ]; then
if [ "$space" = "management" ] || [ "$space" = "management-staging" ] || [ "$space" = "development-ssb" ]; then
cf service "${app_name}-s3" > /dev/null 2>&1 || cf create-service s3 basic "${app_name}-s3" --wait&
cf service "${app_name}-secrets" > /dev/null 2>&1 ||
cf create-user-provided-service "${app_name}-secrets" -p '{"DRAIN_USER":"'$(randpw)'","DRAIN_PASSWORD":"'$(randpw)'"}' &
Expand Down
4 changes: 2 additions & 2 deletions create-space-drain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ cat > manifest.yml << EOF
---
applications:
- name: ${prefix}-space-drain
instances: 1
instances: 0
memory: 64M
no-route: true
EOF

cf drain-space --drain-name "${prefix}-space-drain" "$drain_url"
cf drain-space --drain-name "${prefix}-space-drain" "$drain_url"
13 changes: 3 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,14 @@ services:
timeout: 10s
start_period: 10s
ports:
- "127.0.0.1:4566:4566"
- "127.0.0.1:4571:4571"
- "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # external services port range
environment:
- SERVICES=${SERVICES-}
- DEBUG=${DEBUG-}
- DATA_DIR=${DATA_DIR-}
- LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR-}
- HOST_TMP_FOLDER=${TMPDIR:-/tmp/}localstack
- DOCKER_HOST=unix:///var/run/docker.sock
- AWS_DEFAULT_REGION=us-east-1
volumes:
- "${TMPDIR:-/tmp}/localstack:/tmp/localstack"
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
FuhuXia marked this conversation as resolved.
Show resolved Hide resolved
- "/var/run/docker.sock:/var/run/docker.sock"
- ./localstack.d:/docker-entrypoint-initaws.d


logstash:
depends_on:
Expand Down
43 changes: 42 additions & 1 deletion logstash/logstash.conf
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,52 @@ filter{
# }
# mutate { add_field => { "[@metadata][target_index]" => "index-%{+YYYY.MM}" } }

grok {
match => { "message" => "%{GREEDYDATA:raw_message_content}" }
}
grok {
match => {
"message" => '<%{GREEDYDATA:skip} %{TIMESTAMP_ISO8601:skip} %{DATA:host} %{UUID:proc_id} \[%{DATA:instance_info}\] - \[tags@%{GREEDYDATA:skip} instance_id="%{INT:instance_id}" ip="%{IP:ip}" job="%{GREEDYDATA:skip} space_name="%{DATA:space_name}"\] %{GREEDYDATA:log_data}'
tag_on_failure => []
overwrite => ["message"]
break_on_match => false
}
}
# for message like: catalog-dev.data.gov - [2023-12-15T21:11:49.508628938Z] "GET /0000000 HTTP/1.1" 404 0 21445 "-" "Mozilla/5.0 ..." "127.0.x.x:xxxxx" "10.xx.2.10:xxxxx" x_forwarded_for:"108.xx.xxx.xxx, 64.252.66.xxx, 127.0.x.x" x_forwarded_proto:"https" ... ... b3:xxx
grok {
match => {
"log_data" => '%{HOSTNAME:hostname} - \[%{TIMESTAMP_ISO8601:timestamp}\] "%{WORD:http_method} %{GREEDYDATA:request} %{DATA:http_version}" %{NUMBER:status} %{NUMBER:bytes_sent} %{NUMBER:bytes_received} "%{DATA:http_referer}" "%{DATA:http_user_agent}" %{GREEDYDATA:skip} x_forwarded_for:"%{IP:real_ip}(?:, %{GREEDYDATA:forwarded_ips})*" x_forwarded_proto:%{GREEDYDATA:skip}'
tag_on_failure => []
overwrite => ["message"]
break_on_match => false
}
}
# for message like: 2023-12-14 20:31:53,839 INFO [ckan.config.middleware.flask_app] 404 /dataset/xxxx render time 0.023 seconds
grok {
match => {
"log_data" => '%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:log_level} \[%{DATA:logger}\] %{NUMBER:status:int} %{URIPATH:request_path} render time %{NUMBER:render_time:float} seconds'
tag_on_failure => []
overwrite => ["message"]
break_on_match => false
}
}
if (
([log_data] and [log_data] =~ /^NginxLog/)
FuhuXia marked this conversation as resolved.
Show resolved Hide resolved
or
([hostname] and [http_status] and [hostname] =~ /^logstash-/ and [http_status] == "200")
) {
drop { }
}
mutate {
add_field => { "[@metadata][NEWRELIC_KEY]" => "${NEWRELIC_LICENSE_KEY:notpresent}" }
add_field => { "[@metadata][AWS_S3_PROXY]" => "${AWS_S3_PROXY:notpresent}" }
remove_field => ["skip"]
}
if [space_name] and [space_name] !~ /development/ {
mutate {
remove_field => ["log_data", "raw_message_content"]
}
}

}

output {
Expand Down
7 changes: 3 additions & 4 deletions manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ applications:
APP_NAME: ((app_name))
LS_JAVA_OPTS: ((logstash_java_options))
https_proxy: ((https_proxy))
NEWRELIC_LICENSE_KEY: ((logstash_newrelic_license_key))
NEWRELIC_LOG_URI: ((logstash_newrelic_log_uri))
buildpacks:
- binary_buildpack
health-check-type: process
Expand All @@ -17,7 +19,4 @@ applications:
- route: ((hostname)).((domain))
services:
- ((app_name))-s3
- ((app_name))-secrets
env:
NEWRELIC_LICENSE_KEY: ((logstash_newrelic_license_key))
NEWRELIC_LOG_URI: ((logstash_newrelic_log_uri))
- ((app_name))-secrets
20 changes: 20 additions & 0 deletions vars.development-ssb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
# Name prefix for applications in the logstack.
app_name: logstack

# Options to pass the JVM
logstash_java_options: -Xms512m -Xmx512m
# Number of instances of the Logstash to run.
logstash_instances: 1
# Amount of memory to provide to the Logstash (Java) application.
logstash_memory: 1024
# Assign route for the log shipper. This will be used as the logdrain for other
# Cloud Foundry applications.
hostname: logstash-development-datagov
domain: app.cloud.gov
https_proxy:

# Optional license key for delivering logs to New Relic
# See https://github.com/newrelic/logstash-output-plugin
logstash_newrelic_license_key:
logstash_newrelic_log_uri: https://gov-log-api.newrelic.com/log/v1
Loading