-
Notifications
You must be signed in to change notification settings - Fork 22
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
Submodules #108
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 bbb31de
Merge branch 'master' into stanza
djaglowski 299e800
Updated new operator package
djaglowski 70b145b
Updated changelog ahead of release
djaglowski 44c9adb
Submodule exploration
camdencheek 1dfcc6e
Finished preliminary reorg of operators into modules
djaglowski 46841b9
Merged master
djaglowski c26f895
Fixed google cloud test that was failing on infinite loop
djaglowski af46c61
Fix all tests
djaglowski f51025f
Merged master
djaglowski 420acc7
Update changelog
djaglowski 0fb2bfd
Fix CI build
djaglowski 25b9986
Rename init.go to init_common.go, so that it will not be ignored by a…
djaglowski 0a75e8f
WIP - try fixing tests on windows CI
djaglowski 8567b61
WIP - Try another windows testing approach
djaglowski 32ffdc7
Try uploading joined coverage file
djaglowski 076c485
Run all unit tests for windows, and report all coverage
djaglowski aa15f29
Fix return paths on windows ci tests
djaglowski e0a3134
Try more powershelly command
djaglowski 0cd0842
Clean up makefile and try codecov upload with glob
djaglowski 980cfc3
WIP
camdencheek 1428a52
WIP
camdencheek 14c1b3d
Make disk buffer work
camdencheek d5019df
Add ReadWait
camdencheek 56a019e
Make benchmark for disk buffer
camdencheek 560bb1f
WIP
camdencheek 6e1c1a1
WIP
camdencheek 7fe5b11
WORKING
camdencheek 1a90c8d
Remove debug printlns
camdencheek 9286e20
WIP broken
camdencheek fcb7c7c
Rename to stanza
camdencheek 2a43d87
WIP
camdencheek 711555a
WIP
camdencheek e6ec767
WORKING
camdencheek 364fabe
Remove unnecessary counter
camdencheek 9da4a59
Clean up unused
camdencheek 0f8ccd0
Start of memory buffer
camdencheek e957920
Add slow memory buffer implementation
camdencheek b425ea5
Reorganize package
camdencheek d54d251
Update comments
camdencheek c3f9c28
WIP
camdencheek f9c001e
Improve performance by only seeking when necessary
camdencheek ebe0ad0
WIP
camdencheek 24308f1
WIP
camdencheek d188aab
WIP
camdencheek fa51beb
Fix failure to release semaphore
camdencheek e0c2b94
Some code hygiene
camdencheek 6a2a16d
Add some small tests
camdencheek 71f9159
Make NewConfig return a pointer
camdencheek 0961983
Fix tests
camdencheek 8b75cd5
Tidy
djaglowski 7a52d76
Fix make tidy target
djaglowski e620fd2
Merged in disk-buffers
djaglowski ee559ea
Fix tests and integrate with Google Cloud
camdencheek a04e59b
Fix remaining tests
camdencheek a796934
Appease linter
camdencheek 51d296b
Merge remote-tracking branch 'origin/disk-buffer' into submod-diskbuff
djaglowski 747ac8e
Merged disk buffers again
djaglowski a75331f
Add comments to public functions
camdencheek 1e8d25a
Add test for closing and reopening
camdencheek a2c603e
Add comments to flusher
camdencheek 3bdb9d8
Remove TODO
camdencheek f0051fd
Update diskSizeSemaphore comment
camdencheek 17ce9ab
Update changelog
camdencheek f184e0d
Fis issue with creating files in the buffer package
camdencheek dd952bf
Merged disk-buffer again
djaglowski 5b6b775
Add disk buffers
camdencheek 59b2bb6
Tidy dependencies
camdencheek 2da5b7a
Merged disk-buffer again
djaglowski 18add81
Fix all existing tests
camdencheek dd629c1
Move pollForNewFiles into its own method
camdencheek e7934c6
Deduplicate NewFileReader
camdencheek 580784c
Fix race condition
camdencheek f8965c2
Resolved merge conflicts
djaglowski 8c53231
Update tests
camdencheek e8ca3a8
Fix some lints
camdencheek 48bbe84
Minor fixes
camdencheek 174c138
Close file during move on Windows
camdencheek 8e927d4
Merge branch 'submod-diskbuff' into rc-0.10.0
djaglowski 1e5d36c
Fixed failing test
djaglowski 5a26d73
Added comments, cleaned up stutter
djaglowski 8156ab6
Added multi file test
djaglowski 60b8b03
Improved coverage (#110)
jmwilliams89 53457f2
Added file rotation test
djaglowski ff56186
Merged master
djaglowski a20666b
Merged in master, and improved test coverage
djaglowski 99f3ed5
Merged in submodules
djaglowski 6276c2f
Add LastSeenTime to readers
camdencheek 07dc982
Fix data race
camdencheek 6c8f2d4
Synchronize reading to simplify logic
camdencheek e4ed15e
Update fingerprint on initialize
camdencheek dbb2eb1
Add comments
camdencheek 3f6a663
Remove unnecessary setOffset function
camdencheek a0422ff
Update fingerprint on truncate
camdencheek 82d351e
Add a few tests
camdencheek 49d23ab
Ignore empty lines
camdencheek 9bc0838
File fixes (#113)
camdencheek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.