Skip to content

Commit 69e375c

Browse files
committed
Extend support for logging 5.9 and above versions
Signed-off-by: Jeevan-Darapu <[email protected]>
1 parent dca4a57 commit 69e375c

File tree

12 files changed

+662
-41
lines changed

12 files changed

+662
-41
lines changed

examples/all.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,10 @@ ocp_cluster_logging: false
159159
cluster_log_forwarder: false
160160
cluster_logging_channel: ""
161161
elastic_search_channel: ""
162+
loki_channel: ""
162163
elasticsearch_clf_cs: "" # brew.registry.redhat.io/rh-osbs/iib:111110
163164
clusterlogging_clf_cs: "" # brew.registry.redhat.io/rh-osbs/iib:11111
165+
loki_clf_cs: "" # brew.registry.redhat.io/rh-osbs/iib:111112
164166
log_label: ""
165167
elasticsearch_url: ""
166168
syslog_url: ""

examples/ocp_cluster_logging_vars.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ ocp_cluster_logging: false
33
cluster_log_forwarder: false
44
cluster_logging_channel: ""
55
elastic_search_channel: ""
6+
loki_channel: ""
67
elasticsearch_clf_cs: "" # brew.registry.redhat.io/rh-osbs/iib:111110
78
clusterlogging_clf_cs: "" # brew.registry.redhat.io/rh-osbs/iib:11111
9+
loki_clf_cs: "" # brew.registry.redhat.io/rh-osbs/iib:111112
810
log_label: ""
911
elasticsearch_url: ""
1012
syslog_url: ""
1113
fluentd_url: ""
1214
kafka_url: ""
13-
kafka_path: "" # Location of kafka on external vm ex. /root/kafka/kafka_2.13-2.7.0/bin
15+
kafka_path: "" # Location of kafka on external vm ex. /usr/local/kafka/bin
1416
loki_url: ""
1517
cloudwatch_secret: ""
1618
aws_region: ""

group_vars/all.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@ ocp_cluster_logging: false
4646
cluster_log_forwarder: false
4747
cluster_logging_channel: ""
4848
elastic_search_channel: ""
49+
loki_channel: ""
4950
elasticsearch_clf_cs: "" # brew.registry.redhat.io/rh-osbs/iib:111110
5051
clusterlogging_clf_cs: "" # brew.registry.redhat.io/rh-osbs/iib:11111
52+
loki_clf_cs: "" # brew.registry.redhat.io/rh-osbs/iib:111112
5153
log_label: ""
5254
elasticsearch_url: ""
5355
syslog_url: ""
5456
fluentd_url: ""
5557
kafka_url: ""
56-
kafka_path: "" # Location of kafka on external vm ex. /root/kafka/kafka_2.13-2.7.0/bin
58+
kafka_path: "" # Location of kafka on external vm ex. /usr/local/kafka/bin
5759
loki_url: ""
5860
cloudwatch_secret: ""
5961
aws_region: ""

playbooks/roles/ocp-cluster-logging/files/clf-cleanup.yml

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,27 @@
1616
register: icsp_cnt
1717

1818
- name: Check if the CatalogSource exists
19-
shell: oc get CatalogSource -n openshift-marketplace | grep "cluster-logging\|elasticsearch" |wc -l
20-
register: catalog_src_cnt
19+
shell: oc get CatalogSource -n openshift-marketplace | grep "cluster-logging\|elasticsearch\|loki" | awk 'NR==1{print $1}''NR==2{print $1}''NR==3{print $1}' | xargs
20+
register: catalog_src
2121

2222
- name: Delete ImageContentSourcePolicy if it exists
2323
shell: oc delete ImageContentSourcePolicy brew-registry
2424
when: icsp_cnt.stdout|int == 1
2525

2626
- name: Delete CatalogSource if it exists
27-
shell: oc delete CatalogSource elasticsearch cluster-logging -n openshift-marketplace
28-
when: catalog_src_cnt.stdout|int == 2
27+
shell: oc delete CatalogSource -n openshift-marketplace {{ catalog_src.stdout }}
28+
when: catalog_src.stdout|length > 0
2929

3030
- name: Set disableAllDefaultSources to false
3131
shell: |
3232
oc patch operatorhub.config.openshift.io/cluster -p='{"spec":{"disableAllDefaultSources":false}}' --type=merge
3333
3434
# Check ClusterLogForwarder instance and delete if it exist
35-
- name: Check if the ClutserLogForwarder instance exist
35+
- name: Check if the ClusterLogForwarder instance exist
3636
shell: oc get ClusterLogForwarder -n openshift-logging | wc -l
3737
register: check_clf
3838

39-
- name: Delete ClutserLogForwarder instance if it exists
39+
- name: Delete ClusterLogForwarder instance if it exists
4040
shell: oc delete ClusterLogForwarder instance -n openshift-logging
4141
when: check_clf.stdout|int != 0
4242

@@ -49,6 +49,24 @@
4949
shell: oc delete ClusterLogging instance -n openshift-logging
5050
when: check_cl.stdout|int != 0
5151

52+
# Check Lokistack instance and delete if it exists
53+
- name: Check if the lokistack instance exists
54+
shell: oc get lokistack -n openshift-logging | grep lokistack | awk 'NR==1{print $1}'
55+
register: check_lokistack
56+
57+
- name: Delete lokistack instance if it exists
58+
shell: oc delete lokistack {{ check_lokistack.stdout }} -n openshift-logging
59+
when: check_lokistack.stdout|length > 0
60+
61+
# Check and delete service account for log collection
62+
- name: Check the service account exists
63+
shell: oc get serviceaccount -n openshift-logging | grep logcollector | awk 'NR==1{print $1}'
64+
register: log_sa
65+
66+
- name: Delete the service account
67+
shell: oc delete serviceaccount {{ log_sa.stdout }} -n openshift-logging
68+
when: log_sa.stdout|length > 0
69+
5270
# Check and delete Elasticsearch subscription if it exists
5371
- name: Check if the Elasticsearch subscription exists
5472
shell: oc get subscription -n openshift-operators-redhat | grep elasticsearch-operator | wc -l
@@ -85,3 +103,37 @@
85103
shell: oc delete clusterserviceversion {{ cluster_logging_csv.stdout }} -n openshift-logging
86104
when: cluster_logging_csv.stdout|length > 0
87105

106+
# Check and delete lokistack subscription if it exists
107+
- name: Check if the Loki subscription exists
108+
shell: oc get subscription -n openshift-operators-redhat | grep loki-operator | wc -l
109+
register: loki_subs
110+
111+
- name: Delete Loki subscription if it exists
112+
shell: oc delete subscription loki-operator -n openshift-operators-redhat
113+
when: loki_subs.stdout|int != 0
114+
115+
# Check and delete Loki operator if it exists
116+
- name: Check if the Loki operator exists
117+
shell: oc get csv -n openshift-operators-redhat | grep loki-operator | awk 'NR==1{print $1}'
118+
register: loki_csv
119+
120+
- name: Delete Loki operator if it exists
121+
shell: oc delete clusterserviceversion {{ loki_csv.stdout }} -n openshift-operators-redhat
122+
when: loki_csv.stdout|length > 0
123+
124+
# Delete the Operator groups
125+
- name: Check CLO operator group
126+
shell: oc get operatorgroup -n openshift-logging | grep cluster-logging | awk 'NR==1{print $1}'
127+
register: clo_og
128+
129+
- name: Delete CLO operator group
130+
shell: oc delete operatorgroup {{ clo_og.stdout }} -n openshift-logging
131+
when: clo_og.stdout|length > 0
132+
133+
- name: Check Loki operator group
134+
shell: oc get operatorgroup -n openshift-operators-redhat | grep openshift-operators-redhat | awk 'NR==1{print $1}'
135+
register: loki_og
136+
137+
- name: Delete Loki operator group
138+
shell: oc delete operatorgroup {{ loki_og.stdout }} -n openshift-operators-redhat
139+
when: loki_og.stdout|length > 0

playbooks/roles/ocp-cluster-logging/files/clusterlogforwarder.yml

Lines changed: 79 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,21 @@
2323
src: "{{ role_path }}/templates/clf-instance.yml.j2"
2424
dest: "{{ role_path }}/files/clf-instance.yml"
2525
delegate_to: localhost
26+
when: clo_version | float < 6.0
27+
28+
- name: Generating ClusterLogForwarder file
29+
template:
30+
src: "{{ role_path }}/templates/new-clf-instance.yml.j2"
31+
dest: "{{ role_path }}/files/new-clf-instance.yml"
32+
delegate_to: localhost
33+
when: clo_version | float >= 6.0
2634

2735
# Creating ClusterLogForwarder custom resource
2836
- include_tasks: "{{ role_path }}/files/clf-instance.yml"
37+
when: clo_version | float < 6.0
38+
39+
- include_tasks: "{{ role_path }}/files/new-clf-instance.yml"
40+
when: clo_version | float >= 6.0
2941

3042
# Check if the pods are in good state
3143
- name: Check the logging pods are in good state
@@ -65,23 +77,28 @@
6577
- "loki"
6678
- "cloudwatch"
6779
- "kibana-ldap"
80+
- "lokistack"
6881

6982
- set_fact:
7083
syslog_server_logfile: "/var/log/messages"
7184
external_server_logs_path: "/root/clf_logs"
7285

86+
- name: Pause for 2 minutes to get new logs
87+
pause:
88+
minutes: 2
89+
7390
- name: Fetch the logs from external instances
7491
block:
7592
# Save the logs on external Kafka system and fetch on bastion
7693
- block:
7794
- name: Save the logs on Kafka server
7895
shell: |
7996
mkdir -p {{ external_server_logs_path }}/kafka
80-
{{ kafka_path }}/kafka-console-consumer.sh --bootstrap-server {{ kafka_host }}:9092 --topic {{ log_labels }}-audit --max-messages 10 > {{ external_server_logs_path }}/kafka/audit.txt
81-
{{ kafka_path }}/kafka-console-consumer.sh --bootstrap-server {{ kafka_host }}:9092 --topic {{ log_labels }}-infrastructure --max-messages 10 > {{ external_server_logs_path }}/kafka/infrastructure.txt
82-
{{ kafka_path }}/kafka-console-consumer.sh --bootstrap-server {{ kafka_host }}:9092 --topic {{ log_labels }}-application --max-messages 10 > {{ external_server_logs_path }}/kafka/application.txt
83-
async: 30
84-
poll: 5
97+
{{ kafka_path }}/kafka-console-consumer.sh --bootstrap-server {{ kafka_host }}:9092 --topic {{ app_log_label }} --max-messages 10 > {{ external_server_logs_path }}/kafka/application.txt
98+
{{ kafka_path }}/kafka-console-consumer.sh --bootstrap-server {{ kafka_host }}:9092 --topic {{ audit_log_label }} --max-messages 10 > {{ external_server_logs_path }}/kafka/audit.txt
99+
{{ kafka_path }}/kafka-console-consumer.sh --bootstrap-server {{ kafka_host }}:9092 --topic {{ infra_log_label }} --max-messages 10 > {{ external_server_logs_path }}/kafka/infrastructure.txt
100+
async: 120
101+
poll: 10
85102

86103
- name: Copy the logs file from Kafka to bastion
87104
fetch:
@@ -95,6 +112,26 @@
95112
delegate_to: kafka
96113
when: kafka_server_url is defined
97114

115+
#Make lokistack.sh file executable
116+
- name: Give executable permissions for lokistack.sh file
117+
file:
118+
path: "{{ role_path }}/files/lokistack.sh"
119+
mode: '0555'
120+
state: file
121+
122+
# Check if lokistack exists
123+
- name: Check the Lokistack
124+
shell: oc get lokistack -n openshift-logging | grep lokistack | awk 'NR==1{print $1}'
125+
register: lokistack_present
126+
127+
# Save the logs on external lokistack and fetch on bastion
128+
- name: Save the logs for lokistack instance
129+
shell: |
130+
echo "{{ lokistack_present.stdout }}"
131+
mkdir -p {{ cl_log_dir }}/lokistack
132+
{{ role_path }}/files/lokistack.sh {{ lokistack_present.stdout }}
133+
when: lokistack_present.stdout|length > 0
134+
98135
# Save the logs on external Syslog system and fecth on bastion
99136
- block:
100137
- name: Save the logs on external Syslog instance
@@ -123,22 +160,40 @@
123160
# Fetch logs from Elasticsearch
124161
- name: Fetch Logs from Elasticsearch
125162
shell: |
126-
curl -XGET "{{ elasticsearch_server_url }}/infra*/_search" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [ { "match":{"openshift.labels.logs":"{{ log_labels }}-infrastructure"} } ] } } }' > {{ cl_log_dir }}/elasticsearch/infrastructure.txt
127-
curl -XGET "{{ elasticsearch_server_url }}/audit*/_search" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [ { "match":{"openshift.labels.logs":"{{ log_labels }}-audit"} } ] } } }' > {{ cl_log_dir }}/elasticsearch/audit.txt
128-
curl -XGET "{{ elasticsearch_server_url }}/app*/_search" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [ { "match":{"openshift.labels.logs":"{{ log_labels }}-application"} } ] } } }' > {{ cl_log_dir }}/elasticsearch/application.txt
129-
when: elasticsearch_server_url is defined
163+
curl -XGET "{{ elasticsearch_server_url }}/infra*/_search" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [ { "match":{"openshift.labels.label":"{{ infra_log_label }}"} } ] } } }' > {{ cl_log_dir }}/elasticsearch/infrastructure.txt
164+
curl -XGET "{{ elasticsearch_server_url }}/audit*/_search" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [ { "match":{"openshift.labels.label":"{{ audit_log_label }}"} } ] } } }' > {{ cl_log_dir }}/elasticsearch/audit.txt
165+
curl -XGET "{{ elasticsearch_server_url }}/app*/_search" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [ { "match":{"openshift.labels.label":"{{ app_log_label }}"} } ] } } }' > {{ cl_log_dir }}/elasticsearch/application.txt
166+
when:
167+
- elasticsearch_server_url is defined
168+
- clo_version | float >= 6.0
169+
170+
- name: Fetch Logs from Elasticsearch
171+
shell: |
172+
curl -XGET "{{ elasticsearch_server_url }}/infra*/_search" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [ { "match":{"openshift.labels.logs":"{{ infra_log_label }}"} } ] } } }' > {{ cl_log_dir }}/elasticsearch/infrastructure.txt
173+
curl -XGET "{{ elasticsearch_server_url }}/audit*/_search" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [ { "match":{"openshift.labels.logs":"{{ audit_log_label }}"} } ] } } }' > {{ cl_log_dir }}/elasticsearch/audit.txt
174+
curl -XGET "{{ elasticsearch_server_url }}/app*/_search" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [ { "match":{"openshift.labels.logs":"{{ app_log_label }}"} } ] } } }' > {{ cl_log_dir }}/elasticsearch/application.txt
175+
when:
176+
- elasticsearch_server_url is defined
177+
- clo_version | float <= 5.9
130178

131179
# Fetch logs from Loki
132180
- name: Fetch logs from Loki
133181
shell: |
134182
curl -G -s "{{ loki_server_url }}/api/prom/query" --data-urlencode 'query={log_type="infrastructure"}' > {{ cl_log_dir }}/loki/infrastructure.txt
135183
curl -G -s "{{ loki_server_url }}/api/prom/query" --data-urlencode 'query={log_type="audit"}' > {{ cl_log_dir }}/loki/audit.txt
136184
curl -G -s "{{ loki_server_url }}/api/prom/query" --data-urlencode 'query={log_type="application"}' > {{ cl_log_dir }}/loki/application.txt
185+
async: 120
186+
poll: 10
137187
when: loki_server_url is defined
138188

139189
# Deleting CLF Custom Resource instance because Fluentd and CloudWatch stores the logs on their system
140190
- name: Delete ClusterLogForwarder
141191
shell: oc delete ClusterLogForwarder instance -n openshift-logging
192+
when: clo_version | float <= 5.9
193+
194+
- name: Delete ClusterLogForwarder
195+
shell: oc delete obsclf collector -n openshift-logging
196+
when: clo_version | float >= 6.0
142197

143198
- name: Check the logging pods are restarting
144199
shell: oc get pods -n openshift-logging --no-headers | awk '{if ($3 == "Terminating" ) print $1}' | wc -l
@@ -216,8 +271,19 @@
216271

217272
- name: Elasticsearch clean up
218273
shell: |
219-
curl -X POST "{{ elasticsearch_server_url }}/audit*/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "openshift.labels.logs":"{{ log_labels }}-audit" } }}'
220-
curl -X POST "{{ elasticsearch_server_url }}/app*/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "openshift.labels.logs":"{{ log_labels }}-application" } }}'
221-
curl -X POST "{{ elasticsearch_server_url }}/infra*/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "openshift.labels.logs":"{{ log_labels }}-infrastructure" } }}'
222-
when: elasticsearch_server_url is defined
274+
curl -X POST "{{ elasticsearch_server_url }}/audit*/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "openshift.labels.label":"{{ audit_log_label }}" } }}'
275+
curl -X POST "{{ elasticsearch_server_url }}/app*/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "openshift.labels.label":"{{ app_log_label }}" } }}'
276+
curl -X POST "{{ elasticsearch_server_url }}/infra*/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "openshift.labels.label":"{{ infra_log_label }}" } }}'
277+
when:
278+
- elasticsearch_server_url is defined
279+
- clo_version | float >= 6.0
280+
281+
- name: Elasticsearch clean up
282+
shell: |
283+
curl -X POST "{{ elasticsearch_server_url }}/audit*/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "openshift.labels.logs":"{{ audit_log_label }}" } }}'
284+
curl -X POST "{{ elasticsearch_server_url }}/app*/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "openshift.labels.logs":"{{ app_log_label }}" } }}'
285+
curl -X POST "{{ elasticsearch_server_url }}/infra*/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "openshift.labels.logs":"{{ infra_log_label }}" } }}'
286+
when:
287+
- elasticsearch_server_url is defined
288+
- clo_version | float <= 5.9
223289
ignore_errors: yes

0 commit comments

Comments
 (0)