Skip to content

Commit 607229a

Browse files
committed
removing fluentd setup and updating gcp logging to be used as default
1 parent 7e3b1d3 commit 607229a

File tree

6 files changed

+45
-134
lines changed

6 files changed

+45
-134
lines changed

configs/test/gce/android-init.bash

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,6 @@ echo "Adding workaround to prevent /dev/random hangs."
8080
rm /dev/random
8181
ln -s /dev/urandom /dev/random
8282

83-
echo "Setting up google-fluentd."
84-
curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh
85-
sudo bash install-logging-agent.sh
86-
echo "
87-
<source>
88-
type tcp
89-
format json
90-
port 5170
91-
bind 127.0.0.1
92-
tag bot
93-
</source>
94-
" > /etc/google-fluentd/config.d/clusterfuzz.conf
95-
sed -i 's/flush_interval 5s/flush_interval 60s/' \
96-
/etc/google-fluentd/google-fluentd.conf
97-
sudo service google-fluentd restart
98-
9983
echo "Installing ClusterFuzz package dependencies."
10084
pip install crcmod==1.7 psutil==5.9.4 cryptography==37.0.4 pyOpenSSL==22.0.0
10185

configs/test/gce/windows-init.ps1

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -210,32 +210,6 @@ if (!(Test-Path ($fileName))) {
210210
unzip $fileName
211211
}
212212

213-
# Download and install google-fluentd
214-
$fileName = "$tmp\StackdrvierLogging-v1-3.exe"
215-
if (!(Test-Path ($fileName))) {
216-
$webClient.DownloadFile("https://dl.google.com/cloudagents/windows/StackdriverLogging-v1-3.exe", $fileName)
217-
cmd /c $fileName /S
218-
219-
$configFile = "C:\GoogleStackdriverLoggingAgent\fluent.conf"
220-
$loggingConfig = @"
221-
`r
222-
<source>`r
223-
type tcp`r
224-
format json`r
225-
port 5170`r
226-
bind 127.0.0.1`r
227-
tag bot`r
228-
</source>`r
229-
"@
230-
Add-Content $configFile $loggingConfig
231-
(Get-Content $configFile) -replace "flush_interval 5s","flush_interval 60s" | out-file -encoding ASCII $configFile
232-
233-
Start-Sleep -s 30
234-
235-
net stop fluentdwinsvc
236-
net start fluentdwinsvc
237-
}
238-
239213
# Install NVIDIA driver (Tesla P100).
240214
$nvidiaDriverVersion = "391.29"
241215
$fileName = "$tmp\$nvidiaDriverVersion-tesla-desktop-winserver2016-international.exe"

docker/base/Dockerfile

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,6 @@ RUN echo "deb https://packages.cloud.google.com/apt cloud-sdk main" \
124124
apt-get update -y && \
125125
apt-get install -y google-cloud-sdk
126126

127-
# Set up google-fluentd
128-
# We ignore errors in install-logging-agent.sh as it always fails to start
129-
# after installation without a metadata server.
130-
RUN curl -sSO https://dl.google.com/cloudagents/add-logging-agent-repo.sh && \
131-
bash add-logging-agent-repo.sh --also-install --version=1.10.1 || true && \
132-
sed -i 's/flush_interval 5s/flush_interval 60s/' /etc/google-fluentd/google-fluentd.conf
133-
COPY clusterfuzz-fluentd.conf /etc/google-fluentd/config.d/clusterfuzz.conf
134-
135127
# Common environment variables.
136128
ENV USER=clusterfuzz
137129
ENV INSTALL_DIRECTORY /mnt/scratch0

docker/base/clusterfuzz-fluentd.conf

Lines changed: 0 additions & 7 deletions
This file was deleted.

docker/base/setup_common.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ then
4747
ln -s /dev/urandom /dev/random
4848
fi
4949

50-
# Running without credentials will cause this to fail.
51-
if [[ -z "$LOCAL_SRC" ]]; then
52-
/etc/init.d/google-fluentd restart
53-
fi
54-
5550
# Prevent anything from being written to downloads directory.
5651
mkdir -p /home/$USER/Downloads
5752
chmod 111 /home/$USER/Downloads

src/clusterfuzz/_internal/metrics/logs.py

Lines changed: 45 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,13 @@ def _file_logging_enabled():
8484
'True')) and not _is_running_on_app_engine() and not _is_running_on_k8s()
8585

8686

87-
def _fluentd_logging_enabled():
88-
"""Return bool True where fluentd logging is enabled.
89-
This is enabled by default.
90-
This is disabled for local development and if we are running in app engine or
91-
kubernetes as these have their dedicated loggers, see configure_appengine()
92-
and configure_k8s()."""
93-
return bool(os.getenv('LOG_TO_FLUENTD', 'True')) and not _is_local(
94-
) and not _is_running_on_app_engine() and not _is_running_on_k8s()
95-
96-
9787
def _cloud_logging_enabled():
9888
"""Return bool True where Google Cloud Logging is enabled.
89+
This is enabled by default.
9990
This is disabled for local development and if we are running in a app engine
10091
or kubernetes as these have their dedicated loggers, see
10192
configure_appengine() and configure_k8s()."""
102-
return bool(os.getenv('LOG_TO_GCP')) and not _is_local(
93+
return bool(os.getenv('LOG_TO_GCP', 'True')) and not _is_local(
10394
) and not _is_running_on_app_engine() and not _is_running_on_k8s()
10495

10596

@@ -183,54 +174,54 @@ def truncate(msg, limit):
183174
'...%d characters truncated...' % (len(msg) - limit), msg[-half:]
184175
])
185176

177+
class JsonFormatter(logging.Formatter):
178+
def format(self, record: logging.LogRecord) -> str:
179+
"""Format LogEntry into JSON string."""
180+
entry = {
181+
'message':
182+
truncate(record.getMessage(), STACKDRIVER_LOG_MESSAGE_LIMIT),
183+
'created': (
184+
datetime.datetime.utcfromtimestamp(record.created).isoformat() + 'Z'),
185+
'severity':
186+
record.levelname,
187+
'bot_name':
188+
os.getenv('BOT_NAME'),
189+
'task_payload':
190+
os.getenv('TASK_PAYLOAD'),
191+
'name':
192+
record.name,
193+
'pid':
194+
os.getpid(),
195+
'task_id':
196+
os.getenv('CF_TASK_ID', 'null'),
197+
}
186198

187-
def format_record(record: logging.LogRecord) -> str:
188-
"""Format LogEntry into JSON string."""
189-
entry = {
190-
'message':
191-
truncate(record.getMessage(), STACKDRIVER_LOG_MESSAGE_LIMIT),
192-
'created': (
193-
datetime.datetime.utcfromtimestamp(record.created).isoformat() + 'Z'),
194-
'severity':
195-
record.levelname,
196-
'bot_name':
197-
os.getenv('BOT_NAME'),
198-
'task_payload':
199-
os.getenv('TASK_PAYLOAD'),
200-
'name':
201-
record.name,
202-
'pid':
203-
os.getpid(),
204-
'task_id':
205-
os.getenv('CF_TASK_ID', 'null'),
206-
}
207-
208-
initial_payload = os.getenv('INITIAL_TASK_PAYLOAD')
209-
if initial_payload:
210-
entry['actual_task_payload'] = entry['task_payload']
211-
entry['task_payload'] = initial_payload
199+
initial_payload = os.getenv('INITIAL_TASK_PAYLOAD')
200+
if initial_payload:
201+
entry['actual_task_payload'] = entry['task_payload']
202+
entry['task_payload'] = initial_payload
212203

213-
entry['location'] = getattr(record, 'location', {'error': True})
214-
entry['extras'] = getattr(record, 'extras', {})
215-
update_entry_with_exc(entry, record.exc_info)
204+
entry['location'] = getattr(record, 'location', {'error': True})
205+
entry['extras'] = getattr(record, 'extras', {})
206+
update_entry_with_exc(entry, record.exc_info)
216207

217-
if not entry['extras']:
218-
del entry['extras']
208+
if not entry['extras']:
209+
del entry['extras']
219210

220-
worker_bot_name = os.environ.get('WORKER_BOT_NAME')
221-
if worker_bot_name:
222-
entry['worker_bot_name'] = worker_bot_name
211+
worker_bot_name = os.environ.get('WORKER_BOT_NAME')
212+
if worker_bot_name:
213+
entry['worker_bot_name'] = worker_bot_name
223214

224-
fuzz_target = os.getenv('FUZZ_TARGET')
225-
if fuzz_target:
226-
entry['fuzz_target'] = fuzz_target
215+
fuzz_target = os.getenv('FUZZ_TARGET')
216+
if fuzz_target:
217+
entry['fuzz_target'] = fuzz_target
227218

228-
# Log bot shutdown cases as WARNINGs since this is expected for preemptibles.
229-
if (entry['severity'] in ['ERROR', 'CRITICAL'] and
230-
'IOError: [Errno 4] Interrupted function call' in entry['message']):
231-
entry['severity'] = 'WARNING'
219+
# Log bot shutdown cases as WARNINGs since this is expected for preemptibles.
220+
if (entry['severity'] in ['ERROR', 'CRITICAL'] and
221+
'IOError: [Errno 4] Interrupted function call' in entry['message']):
222+
entry['severity'] = 'WARNING'
232223

233-
return json.dumps(entry, default=_handle_unserializable)
224+
return json.dumps(entry, default=_handle_unserializable)
234225

235226

236227
def _handle_unserializable(unserializable: Any) -> str:
@@ -271,16 +262,6 @@ def update_entry_with_exc(entry, exc_info):
271262
}
272263

273264

274-
class JsonSocketHandler(logging.handlers.SocketHandler):
275-
"""Format log into JSON string before sending it to fluentd. We need this
276-
because SocketHandler doesn't respect the formatter attribute."""
277-
278-
def makePickle(self, record: logging.LogRecord):
279-
"""Format LogEntry into JSON string."""
280-
# \n is the recognized delimiter by fluentd's in_tcp. Don't remove.
281-
return (format_record(record) + '\n').encode('utf-8')
282-
283-
284265
def uncaught_exception_handler(exception_type, exception_value,
285266
exception_traceback):
286267
"""Handles any exception that are uncaught by logging an error and calling
@@ -358,14 +339,6 @@ def record_factory(*args, **kwargs):
358339
logging.getLogger().setLevel(logging.INFO)
359340

360341

361-
def configure_fluentd_logging():
362-
fluentd_handler = JsonSocketHandler(
363-
host='127.0.0.1',
364-
port=5170,
365-
)
366-
fluentd_handler.setLevel(logging.INFO)
367-
logging.getLogger().addHandler(fluentd_handler)
368-
369342

370343
def configure_cloud_logging():
371344
""" Configure Google cloud logging, for bots not running on appengine nor k8s.
@@ -412,6 +385,8 @@ def cloud_label_filter(record):
412385

413386
handler.addFilter(cloud_label_filter)
414387
handler.setLevel(logging.INFO)
388+
formatter = JsonFormatter()
389+
handler.setFormatter(formatter)
415390

416391
logging.getLogger().addHandler(handler)
417392

@@ -434,8 +409,6 @@ def configure(name, extras=None):
434409
logging.basicConfig(level=logging.INFO)
435410
if _file_logging_enabled():
436411
config.dictConfig(get_logging_config_dict(name))
437-
if _fluentd_logging_enabled():
438-
configure_fluentd_logging()
439412
if _cloud_logging_enabled():
440413
configure_cloud_logging()
441414
logger = logging.getLogger(name)

0 commit comments

Comments
 (0)