Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submodules #108

Merged
merged 97 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
ca5a6cf
Renamed package to stanza
djaglowski Aug 24, 2020
bbb31de
Merge branch 'master' into stanza
djaglowski Aug 24, 2020
299e800
Updated new operator package
djaglowski Aug 24, 2020
70b145b
Updated changelog ahead of release
djaglowski Aug 24, 2020
44c9adb
Submodule exploration
camdencheek Aug 27, 2020
1dfcc6e
Finished preliminary reorg of operators into modules
djaglowski Sep 1, 2020
46841b9
Merged master
djaglowski Sep 1, 2020
c26f895
Fixed google cloud test that was failing on infinite loop
djaglowski Sep 1, 2020
af46c61
Fix all tests
djaglowski Sep 1, 2020
f51025f
Merged master
djaglowski Sep 1, 2020
420acc7
Update changelog
djaglowski Sep 1, 2020
0fb2bfd
Fix CI build
djaglowski Sep 1, 2020
25b9986
Rename init.go to init_common.go, so that it will not be ignored by a…
djaglowski Sep 1, 2020
0a75e8f
WIP - try fixing tests on windows CI
djaglowski Sep 1, 2020
8567b61
WIP - Try another windows testing approach
djaglowski Sep 1, 2020
32ffdc7
Try uploading joined coverage file
djaglowski Sep 1, 2020
076c485
Run all unit tests for windows, and report all coverage
djaglowski Sep 1, 2020
aa15f29
Fix return paths on windows ci tests
djaglowski Sep 1, 2020
e0a3134
Try more powershelly command
djaglowski Sep 1, 2020
0cd0842
Clean up makefile and try codecov upload with glob
djaglowski Sep 1, 2020
980cfc3
WIP
camdencheek Aug 11, 2020
1428a52
WIP
camdencheek Aug 12, 2020
14c1b3d
Make disk buffer work
camdencheek Aug 21, 2020
d5019df
Add ReadWait
camdencheek Aug 21, 2020
56a019e
Make benchmark for disk buffer
camdencheek Aug 21, 2020
560bb1f
WIP
camdencheek Aug 24, 2020
6e1c1a1
WIP
camdencheek Aug 25, 2020
7fe5b11
WORKING
camdencheek Aug 25, 2020
1a90c8d
Remove debug printlns
camdencheek Aug 25, 2020
9286e20
WIP broken
camdencheek Aug 26, 2020
fcb7c7c
Rename to stanza
camdencheek Aug 27, 2020
2a43d87
WIP
camdencheek Aug 27, 2020
711555a
WIP
camdencheek Aug 28, 2020
e6ec767
WORKING
camdencheek Aug 28, 2020
364fabe
Remove unnecessary counter
camdencheek Aug 28, 2020
9da4a59
Clean up unused
camdencheek Aug 28, 2020
0f8ccd0
Start of memory buffer
camdencheek Aug 31, 2020
e957920
Add slow memory buffer implementation
camdencheek Aug 31, 2020
b425ea5
Reorganize package
camdencheek Aug 31, 2020
d54d251
Update comments
camdencheek Aug 31, 2020
c3f9c28
WIP
camdencheek Aug 31, 2020
f9c001e
Improve performance by only seeking when necessary
camdencheek Aug 31, 2020
ebe0ad0
WIP
camdencheek Aug 31, 2020
24308f1
WIP
camdencheek Sep 1, 2020
d188aab
WIP
camdencheek Sep 1, 2020
fa51beb
Fix failure to release semaphore
camdencheek Sep 1, 2020
e0c2b94
Some code hygiene
camdencheek Sep 1, 2020
6a2a16d
Add some small tests
camdencheek Sep 1, 2020
71f9159
Make NewConfig return a pointer
camdencheek Sep 1, 2020
0961983
Fix tests
camdencheek Sep 1, 2020
8b75cd5
Tidy
djaglowski Sep 1, 2020
7a52d76
Fix make tidy target
djaglowski Sep 2, 2020
e620fd2
Merged in disk-buffers
djaglowski Sep 3, 2020
ee559ea
Fix tests and integrate with Google Cloud
camdencheek Sep 3, 2020
a04e59b
Fix remaining tests
camdencheek Sep 3, 2020
a796934
Appease linter
camdencheek Sep 3, 2020
51d296b
Merge remote-tracking branch 'origin/disk-buffer' into submod-diskbuff
djaglowski Sep 3, 2020
747ac8e
Merged disk buffers again
djaglowski Sep 3, 2020
a75331f
Add comments to public functions
camdencheek Sep 3, 2020
1e8d25a
Add test for closing and reopening
camdencheek Sep 3, 2020
a2c603e
Add comments to flusher
camdencheek Sep 3, 2020
3bdb9d8
Remove TODO
camdencheek Sep 3, 2020
f0051fd
Update diskSizeSemaphore comment
camdencheek Sep 3, 2020
17ce9ab
Update changelog
camdencheek Sep 3, 2020
f184e0d
Fis issue with creating files in the buffer package
camdencheek Sep 3, 2020
dd952bf
Merged disk-buffer again
djaglowski Sep 3, 2020
5b6b775
Add disk buffers
camdencheek Sep 3, 2020
59b2bb6
Tidy dependencies
camdencheek Sep 3, 2020
2da5b7a
Merged disk-buffer again
djaglowski Sep 3, 2020
18add81
Fix all existing tests
camdencheek Sep 7, 2020
dd629c1
Move pollForNewFiles into its own method
camdencheek Sep 8, 2020
e7934c6
Deduplicate NewFileReader
camdencheek Sep 8, 2020
580784c
Fix race condition
camdencheek Sep 8, 2020
f8965c2
Resolved merge conflicts
djaglowski Sep 8, 2020
8c53231
Update tests
camdencheek Sep 8, 2020
e8ca3a8
Fix some lints
camdencheek Sep 8, 2020
48bbe84
Minor fixes
camdencheek Sep 8, 2020
174c138
Close file during move on Windows
camdencheek Sep 8, 2020
8e927d4
Merge branch 'submod-diskbuff' into rc-0.10.0
djaglowski Sep 8, 2020
1e5d36c
Fixed failing test
djaglowski Sep 8, 2020
5a26d73
Added comments, cleaned up stutter
djaglowski Sep 8, 2020
8156ab6
Added multi file test
djaglowski Sep 8, 2020
60b8b03
Improved coverage (#110)
jmwilliams89 Sep 9, 2020
53457f2
Added file rotation test
djaglowski Sep 9, 2020
ff56186
Merged master
djaglowski Sep 9, 2020
a20666b
Merged in master, and improved test coverage
djaglowski Sep 9, 2020
99f3ed5
Merged in submodules
djaglowski Sep 9, 2020
6276c2f
Add LastSeenTime to readers
camdencheek Sep 9, 2020
07dc982
Fix data race
camdencheek Sep 9, 2020
6c8f2d4
Synchronize reading to simplify logic
camdencheek Sep 9, 2020
e4ed15e
Update fingerprint on initialize
camdencheek Sep 9, 2020
dbb2eb1
Add comments
camdencheek Sep 9, 2020
3f6a663
Remove unnecessary setOffset function
camdencheek Sep 9, 2020
a0422ff
Update fingerprint on truncate
camdencheek Sep 9, 2020
82d351e
Add a few tests
camdencheek Sep 9, 2020
49d23ab
Ignore empty lines
camdencheek Sep 9, 2020
9bc0838
File fixes (#113)
camdencheek Sep 11, 2020
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
30 changes: 27 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
name: Run Unit Tests
command: make test
- codecov/upload:
file: ./coverage.txt
file: '**/coverage.txt'

test-macos:
executor: mac
Expand Down Expand Up @@ -138,7 +138,31 @@ jobs:
- run:
name: Unit Tests
shell: powershell.exe
command: go test -race -coverprofile coverage.txt -coverpkg ./... ./...
command: >
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm certain there is a better way to do this that doesn't involve listing each module manually, but I figure we can handle that later.

go test -race ./...; `
Push-Location; Set-Location ./cmd/stanza; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/input/file; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/input/journald; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/input/windows; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/input/k8sevent; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/input/tcp; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/input/udp; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/output/elastic; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/output/file; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/output/googlecloud; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/output/stdout; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/parser/json; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/parser/regex; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/parser/severity; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/parser/syslog; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/parser/time; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/transformer/filter; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/transformer/hostmetadata; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/transformer/k8smetadata; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/transformer/metadata; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/transformer/ratelimit; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/transformer/restructure; go test -race ./...; Pop-Location; `
Push-Location; Set-Location ./operator/builtin/transformer/router; go test -race ./...; Pop-Location;

run-benchmark:
parameters:
Expand Down Expand Up @@ -178,7 +202,7 @@ jobs:
command: mkdir {bin,out,tmp}
- run:
name: Build Stanza Agent
command: GOPROXY=direct go build -v -o ./bin/stanza ./
command: (cd ./cmd/stanza && GO111MODULE=on GOPROXY=direct go build -v -o ../../bin/stanza ./)
- run:
name: Build Log Bench
command: GOPROXY=direct go get github.com/observiq/amazon-log-agent-benchmark-tool/cmd/logbench/ &&
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
dev/*
.DS_Store
tmp/*
coverage.txt
coverage.html
local/*
**/coverage.txt
**/coverage.html
artifacts/*
.vscode/*
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Split buffers into buffers and flushers for better modularity
- New memory buffer design for a uniform interface between disk and memory buffers
- Most operators are now dedicated modules, so that they may be imported individually

## [0.9.14] - 2020-08-31
### Fixed
Expand Down
35 changes: 30 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ GOARCH=$(shell go env GOARCH)

GIT_SHA=$(shell git rev-parse --short HEAD)

PROJECT_ROOT = $(shell pwd)
ARTIFACTS = ${PROJECT_ROOT}/artifacts
ALL_MODULES := $(shell find . -type f -name "go.mod" -exec dirname {} \; | sort )

BUILD_INFO_IMPORT_PATH=github.com/observiq/stanza/internal/version
BUILD_X1=-X $(BUILD_INFO_IMPORT_PATH).GitHash=$(GIT_SHA)
ifdef VERSION
Expand All @@ -18,12 +22,26 @@ install-tools:

.PHONY: test
test:
go test -race -coverprofile coverage.txt -coverpkg ./... ./...
go tool cover -html=coverage.txt -o coverage.html
$(MAKE) for-all CMD="go test -race -coverprofile coverage.txt -coverpkg ./... ./..."

.PHONY: bench
bench:
go test -run=NONE -bench '.*' ./... -benchmem
$(MAKE) for-all CMD="go test -run=NONE -bench '.*' ./... -benchmem"

.PHONY: clean
clean:
rm -fr ./artifacts
$(MAKE) for-all CMD="rm -f coverage.txt coverage.html"

.PHONY: tidy
tidy:
$(MAKE) for-all CMD="go mod tidy"

.PHONY: listmod
listmod:
@set -e; for dir in $(ALL_MODULES); do \
(echo "$${dir}"); \
done

.PHONY: lint
lint:
Expand All @@ -35,11 +53,11 @@ generate:

.PHONY: build
build:
CGO_ENABLED=0 go build -o ./artifacts/stanza_$(GOOS)_$(GOARCH) $(BUILD_INFO) .
(cd ./cmd/stanza && CGO_ENABLED=0 go build -o ../../artifacts/stanza_$(GOOS)_$(GOARCH) $(BUILD_INFO) .)

.PHONY: install
install:
CGO_ENABLED=0 go install $(BUILD_INFO) .
(cd ./cmd/stanza && CGO_ENABLED=0 go install $(BUILD_INFO) .)

.PHONY: build-all
build-all: build-darwin-amd64 build-linux-amd64 build-windows-amd64
Expand All @@ -55,3 +73,10 @@ build-linux-amd64:
.PHONY: build-windows-amd64
build-windows-amd64:
@GOOS=windows GOARCH=amd64 $(MAKE) build

.PHONY: for-all
for-all:
@$${CMD}
@set -e; for dir in $(ALL_MODULES); do \
(cd "$${dir}" && $${CMD} ); \
done
117 changes: 15 additions & 102 deletions agent/agent.go
Original file line number Diff line number Diff line change
@@ -1,134 +1,47 @@
package agent

import (
"fmt"
"os"
"path/filepath"
"sync"
"time"

"github.com/observiq/stanza/errors"
"github.com/observiq/stanza/operator"
_ "github.com/observiq/stanza/operator/builtin" // register operators
"github.com/observiq/stanza/database"
"github.com/observiq/stanza/pipeline"
"go.etcd.io/bbolt"
"go.uber.org/zap"
)

// LogAgent is an entity that handles log monitoring.
type LogAgent struct {
database operator.Database
pipeline *pipeline.Pipeline
database database.Database
pipeline pipeline.Pipeline

startOnce sync.Once
stopOnce sync.Once

*zap.SugaredLogger
}

// Start will start the log monitoring process.
// Start will start the log monitoring process
func (a *LogAgent) Start() (err error) {
a.startOnce.Do(func() {
err = a.pipeline.Start()
if err != nil {
return
}
a.Info("Agent started")
})
return
}

// Stop will stop the log monitoring process.
func (a *LogAgent) Stop() {
// Stop will stop the log monitoring process
func (a *LogAgent) Stop() (err error) {
a.stopOnce.Do(func() {
a.pipeline.Stop()
a.database.Close()
a.Info("Agent stopped")
})
}

// OpenDatabase will open and create a database.
func OpenDatabase(file string) (operator.Database, error) {
if file == "" {
return operator.NewStubDatabase(), nil
}

if _, err := os.Stat(filepath.Dir(file)); err != nil {
if os.IsNotExist(err) {
err := os.MkdirAll(filepath.Dir(file), 0755)
if err != nil {
return nil, fmt.Errorf("creating database directory: %s", err)
}
} else {
return nil, err
err = a.pipeline.Stop()
if err != nil {
return
}
}

options := &bbolt.Options{Timeout: 1 * time.Second}
return bbolt.Open(file, 0666, options)
}

// LogAgentBuilder is a construct used to build a log agent
type LogAgentBuilder struct {
cfg *Config
logger *zap.SugaredLogger
pluginDir string
databaseFile string
defaultOutput operator.Operator
}

// NewBuilder creates a new LogAgentBuilder
func NewBuilder(cfg *Config, logger *zap.SugaredLogger) *LogAgentBuilder {
return &LogAgentBuilder{
cfg: cfg,
logger: logger,
}
}

// WithPluginDir adds the specified plugin directory when building a log agent
func (b *LogAgentBuilder) WithPluginDir(pluginDir string) *LogAgentBuilder {
b.pluginDir = pluginDir
return b
}

// WithDatabaseFile adds the specified database file when building a log agent
func (b *LogAgentBuilder) WithDatabaseFile(databaseFile string) *LogAgentBuilder {
b.databaseFile = databaseFile
return b
}

// WithDefaultOutput adds a default output when building a log agent
func (b *LogAgentBuilder) WithDefaultOutput(defaultOutput operator.Operator) *LogAgentBuilder {
b.defaultOutput = defaultOutput
return b
}

// Build will build a new log agent using the values defined on the builder
func (b *LogAgentBuilder) Build() (*LogAgent, error) {
database, err := OpenDatabase(b.databaseFile)
if err != nil {
return nil, errors.Wrap(err, "open database")
}

registry, err := operator.NewPluginRegistry(b.pluginDir)
if err != nil {
return nil, errors.Wrap(err, "load plugin registry")
}

buildContext := operator.BuildContext{
Logger: b.logger,
PluginRegistry: registry,
Database: database,
}

pipeline, err := b.cfg.Pipeline.BuildPipeline(buildContext, b.defaultOutput)
if err != nil {
return nil, err
}

return &LogAgent{
pipeline: pipeline,
database: database,
SugaredLogger: b.logger,
}, nil
err = a.database.Close()
if err != nil {
return
}
})
return
}
Loading