Skip to content

Commit 4cd2625

Browse files
committed
GCE/Windows: enable stackdriver logging agent
This change bumps the stackdriver logging agent version to v1-9, re-enable it, and change the script/configuration to: * Create /var/log in the startup script, since the fluentd configuration expects the directory to exists * Add support for collecting kubelet/kube-proxy logs
1 parent 05074e9 commit 4cd2625

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

cluster/gce/windows/configure.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ try {
112112
Set-EnvironmentVars
113113
Create-Directories
114114
Download-HelperScripts
115-
# Disable Stackdrver logging until issue is fixed.
116-
# InstallAndStart-LoggingAgent
115+
InstallAndStart-LoggingAgent
117116

118117
Create-DockerRegistryKey
119118
DownloadAndInstall-KubernetesBinaries

cluster/gce/windows/k8s-node-setup.psm1

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,13 @@ function Disable-WindowsDefender {
270270
# Creates directories where other functions in this module will read and write
271271
# data.
272272
# Note: C:\tmp is required for running certain kubernetes tests.
273+
# C:\var\log is used by kubelet to stored container logs and also
274+
# hard-coded in the fluentd/stackdriver config for log collection.
273275
function Create-Directories {
274276
Log-Output "Creating ${env:K8S_DIR} and its subdirectories."
275277
ForEach ($dir in ("${env:K8S_DIR}", "${env:NODE_DIR}", "${env:LOGS_DIR}",
276278
"${env:CNI_DIR}", "${env:CNI_CONFIG_DIR}", "${env:MANIFESTS_DIR}",
277-
"${env:PKI_DIR}"), "C:\tmp") {
279+
"${env:PKI_DIR}"), "C:\tmp", "C:\var\log") {
278280
mkdir -Force $dir
279281
}
280282
}
@@ -1059,7 +1061,7 @@ function Create-DockerRegistryKey {
10591061
# TODO(pjh): move the Stackdriver logging agent code below into a separate
10601062
# module; it was put here temporarily to avoid disrupting the file layout in
10611063
# the K8s release machinery.
1062-
$STACKDRIVER_VERSION = 'v1-8'
1064+
$STACKDRIVER_VERSION = 'v1-9'
10631065
$STACKDRIVER_ROOT = 'C:\Program Files (x86)\Stackdriver'
10641066

10651067
# Install and start the Stackdriver logging agent according to
@@ -1123,9 +1125,6 @@ function InstallAndStart-LoggingAgent {
11231125
Remove-Item -Force -Recurse $tmp_dir
11241126
}
11251127

1126-
# TODO(yujuhong):
1127-
# - Collect kubelet/kube-proxy logs.
1128-
# - Add tag for kubernetes node name.
11291128
$FLUENTD_CONFIG = @'
11301129
# This configuration file for Fluentd is used to watch changes to kubernetes
11311130
# container logs in the directory /var/lib/docker/containers/ and submit the
@@ -1184,6 +1183,34 @@ $FLUENTD_CONFIG = @'
11841183
read_from_head true
11851184
</source>
11861185
1186+
# Example:
1187+
# I0204 07:32:30.020537 3368 server.go:1048] POST /stats/container/: (13.972191ms) 200 [[Go-http-client/1.1] 10.244.1.3:40537]
1188+
<source>
1189+
@type tail
1190+
format multiline
1191+
multiline_flush_interval 5s
1192+
format_firstline /^\w\d{4}/
1193+
format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/
1194+
time_format %m%d %H:%M:%S.%N
1195+
path /etc/kubernetes/logs/kubelet.log
1196+
pos_file /etc/kubernetes/logs/gcp-kubelet.log.pos
1197+
tag kubelet
1198+
</source>
1199+
1200+
# Example:
1201+
# I1118 21:26:53.975789 6 proxier.go:1096] Port "nodePort for kube-system/default-http-backend:http" (:31429/tcp) was open before and is still needed
1202+
<source>
1203+
@type tail
1204+
format multiline
1205+
multiline_flush_interval 5s
1206+
format_firstline /^\w\d{4}/
1207+
format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/
1208+
time_format %m%d %H:%M:%S.%N
1209+
path /etc/kubernetes/logs/kube-proxy.log
1210+
pos_file /etc/kubernetes/logs/gcp-kube-proxy.log.pos
1211+
tag kube-proxy
1212+
</source>
1213+
11871214
<match reform.**>
11881215
@type record_reformer
11891216
enable_ruby true
@@ -1203,7 +1230,17 @@ $FLUENTD_CONFIG = @'
12031230
tag ${if record['stream'] == 'stderr' then 'raw.stderr' else 'raw.stdout' end}
12041231
remove_keys stream,log
12051232
</match>
1206-
'@
1233+
1234+
# Attach local_resource_id for 'k8s_node' monitored resource.
1235+
<filter **>
1236+
@type record_transformer
1237+
enable_ruby true
1238+
<record>
1239+
"logging.googleapis.com/local_resource_id" ${"k8s_node.NODE_NAME"}
1240+
</record>
1241+
</filter>
1242+
'@.replace('NODE_NAME', (hostname))
1243+
12071244

12081245
# Export all public functions:
12091246
Export-ModuleMember -Function *-*

0 commit comments

Comments
 (0)