Skip to content

Commit adc587f

Browse files
committed
Support filelog watching in Windows.
1 parent b951f24 commit adc587f

File tree

5 files changed

+45
-20
lines changed

5 files changed

+45
-20
lines changed

Makefile

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ CGO_ENABLED:=0
6565
# Construct the "-tags" parameter used by "go build".
6666
BUILD_TAGS?=
6767

68+
LINUX_BUILD_TAGS = $(BUILD_TAGS)
69+
WINDOWS_BUILD_TAGS = $(BUILD_TAGS)
70+
6871
ifeq ($(ENABLE_JOURNALD), 1)
6972
# Enable journald build tag.
70-
BUILD_TAGS:=$(BUILD_TAGS) journald
73+
LINUX_BUILD_TAGS := $(BUILD_TAGS) journald
7174
# Enable cgo because sdjournal needs cgo to compile. The binary will be
7275
# dynamically linked if CGO_ENABLED is enabled. This is fine because fedora
7376
# already has necessary dynamic library. We can not use `-extldflags "-static"`
@@ -82,9 +85,9 @@ else
8285
endif
8386

8487
vet:
85-
GO111MODULE=on go list -mod vendor -tags "$(BUILD_TAGS)" ./... | \
88+
GO111MODULE=on go list -mod vendor -tags "$(LINUX_BUILD_TAGS)" ./... | \
8689
grep -v "./vendor/*" | \
87-
GO111MODULE=on xargs go vet -mod vendor -tags "$(BUILD_TAGS)"
90+
GO111MODULE=on xargs go vet -mod vendor -tags "$(LINUX_BUILD_TAGS)"
8891

8992
fmt:
9093
find . -type f -name "*.go" | grep -v "./vendor/*" | xargs gofmt -s -w -l
@@ -110,8 +113,8 @@ endif
110113
-mod vendor \
111114
-o $@ \
112115
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
113-
-tags "$(BUILD_TAGS)" \
114-
./cmd/$(subst -,,$*)/$(subst -,_,$*).go
116+
-tags "$(WINDOWS_BUILD_TAGS)" \
117+
./cmd/$(subst -,,$*)
115118
touch $@
116119

117120
./test/bin/windows_amd64/%.exe: $(PKG_SOURCES)
@@ -121,24 +124,24 @@ endif
121124
GOOS=windows GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) GO111MODULE=on go build \
122125
-mod vendor \
123126
-o $@ \
124-
-tags "$(BUILD_TAGS)" \
125-
./test/e2e/$(subst -,,$*)/$(subst -,_,$*).go
127+
-tags "$(WINDOWS_BUILD_TAGS)" \
128+
./test/e2e/$(subst -,,$*)
126129

127130
bin/linux_amd64/%: $(PKG_SOURCES)
128131
GOOS=linux GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) GO111MODULE=on go build \
129132
-mod vendor \
130133
-o $@ \
131134
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
132-
-tags "$(BUILD_TAGS)" \
133-
./cmd/$(subst -,,$*)/$(subst -,_,$*).go
135+
-tags "$(LINUX_BUILD_TAGS)" \
136+
./cmd/$(subst -,,$*)
134137
touch $@
135138

136139
./test/bin/linux_amd64/%: $(PKG_SOURCES)
137140
GOOS=linux GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) GO111MODULE=on go build \
138141
-mod vendor \
139142
-o $@ \
140-
-tags "$(BUILD_TAGS)" \
141-
./test/e2e/$(subst -,,$*)/$(subst -,_,$*).go
143+
-tags "$(LINUX_BUILD_TAGS)" \
144+
./test/e2e/$(subst -,,$*)
142145

143146
ifneq ($(ENABLE_JOURNALD), 1)
144147
bin/linux_amd64/log-counter:
@@ -152,7 +155,7 @@ ifeq ($(ENABLE_JOURNALD), 1)
152155
-mod vendor \
153156
-o bin/log-counter \
154157
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
155-
-tags "$(BUILD_TAGS)" \
158+
-tags "$(LINUX_BUILD_TAGS)" \
156159
cmd/logcounter/log_counter.go
157160
else
158161
echo "Warning: log-counter requires journald, skipping."
@@ -163,29 +166,29 @@ endif
163166
-mod vendor \
164167
-o bin/node-problem-detector \
165168
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
166-
-tags "$(BUILD_TAGS)" \
169+
-tags "$(LINUX_BUILD_TAGS)" \
167170
./cmd/nodeproblemdetector
168171

169172
./test/bin/problem-maker: $(PKG_SOURCES)
170173
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GO111MODULE=on go build \
171174
-mod vendor \
172175
-o test/bin/problem-maker \
173-
-tags "$(BUILD_TAGS)" \
176+
-tags "$(LINUX_BUILD_TAGS)" \
174177
./test/e2e/problemmaker/problem_maker.go
175178

176179
./bin/health-checker: $(PKG_SOURCES)
177180
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GO111MODULE=on go build \
178181
-mod vendor \
179182
-o bin/health-checker \
180183
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
181-
-tags "$(BUILD_TAGS)" \
184+
-tags "$(LINUX_BUILD_TAGS)" \
182185
cmd/healthchecker/health_checker.go
183186

184187
test: vet fmt
185-
GO111MODULE=on go test -mod vendor -timeout=1m -v -race -short -tags "$(BUILD_TAGS)" ./...
188+
GO111MODULE=on go test -mod vendor -timeout=1m -v -race -short -tags "$(LINUX_BUILD_TAGS)" ./...
186189

187190
e2e-test: vet fmt build-tar
188-
GO111MODULE=on ginkgo -nodes=$(PARALLEL) -mod vendor -timeout=10m -v -tags "$(BUILD_TAGS)" -stream \
191+
GO111MODULE=on ginkgo -nodes=$(PARALLEL) -mod vendor -timeout=10m -v -tags "$(LINUX_BUILD_TAGS)" -stream \
189192
./test/e2e/metriconly/... -- \
190193
-project=$(PROJECT) -zone=$(ZONE) \
191194
-image=$(VM_IMAGE) -image-family=$(IMAGE_FAMILY) -image-project=$(IMAGE_PROJECT) \
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"plugin": "filelog",
3+
"pluginConfig": {
4+
"timestamp": "^time=\"(\\S*)\"",
5+
"message": "msg=\"([^\n]*)\"",
6+
"timestampFormat": "2006-01-02T15:04:05.999999999-07:00"
7+
},
8+
"logPath": "C:\\Program Files\\containerd\\containerd.log",
9+
"lookback": "5m",
10+
"bufferSize": 10,
11+
"source": "docker-monitor",
12+
"conditions": [],
13+
"rules": [
14+
{
15+
"type": "temporary",
16+
"reason": "BadCNIConfig",
17+
"pattern": "failed to reload cni configuration.*"
18+
}
19+
]
20+
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
github.com/go-ole/go-ole v1.2.4 // indirect
1616
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
1717
github.com/google/cadvisor v0.36.0
18+
github.com/hpcloud/tail v1.0.0
1819
github.com/onsi/ginkgo v1.10.3
1920
github.com/onsi/gomega v1.7.1
2021
github.com/pborman/uuid v1.2.0

pkg/systemlogmonitor/logwatchers/filelog/log_watcher_windows.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ limitations under the License.
1717
package filelog
1818

1919
import (
20-
"fmt"
2120
"io"
21+
22+
"github.com/hpcloud/tail"
2223
)
2324

2425
// getLogReader returns log reader for filelog log. Note that getLogReader doesn't look back
2526
// to the rolled out logs.
2627
func getLogReader(path string) (io.ReadCloser, error) {
27-
// TODO: Support this on windows.
28-
return nil, fmt.Errorf("not supported on windows.")
28+
return tail.OpenFile(path)
2929
}

vendor/modules.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ github.com/hashicorp/errwrap
122122
# github.com/hashicorp/go-multierror v0.0.0-20171204182908-b7773ae21874
123123
github.com/hashicorp/go-multierror
124124
# github.com/hpcloud/tail v1.0.0
125+
## explicit
125126
github.com/hpcloud/tail
126127
github.com/hpcloud/tail/ratelimiter
127128
github.com/hpcloud/tail/util

0 commit comments

Comments
 (0)