8000 Consider publishing tailer separately · Issue #199 · google/mtail · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Consider publishing tailer separately #199

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

Open
sgtsquiggs opened this issue Dec 20, 2018 · 6 comments
Open

Consider publishing tailer separately #199

sgtsquiggs opened this issue Dec 20, 2018 · 6 comments
Labels
enhancement This is considered a feature request, not currently guaranteed by the code or design today process Issues related to process and CI

Comments

@sgtsquiggs
Copy link

Hi,

I'm currently using a chunk of mtail as a replacement for hpcloud/tail. I was previously pulling google/mtail/[tailer,watcher,logline], but with the latest changes on master this isn't possible anymore. I agree with the move to internal and I can always maintain my own copy and make updates but it would be very useful to have the tail implementation in mtail exposed as a standalone library. It's outside of the scope of mtail to expose a library, but maybe useful to the golang community as a whole :)

@jaqx0r
Copy link
Contributor
jaqx0r commented Dec 21, 2018 via email

@sgtsquiggs
Copy link
Author

My usage is very roughly like:

func (t *Tail) Start() error {
	t.Lock()
	defer t.Unlock()
	t.lines := make(chan *logline.LogLine)
	t.watcher := watcher.NewLogWatcher(pollDuration, !poll)
	if err != nil {
		defer close(t.lines)
		return err
	}
	var opts []func(*tailer.Tailer) error
	if t.FromBeginning {
		opts = append(opts, tailer.OneShot)
	}
	t.tailer, err := tailer.New(t.lines, afero.NewOsFs(), t.watcher, opts...)
	if err != nil {
		defer t.watcher.Close()
		defer close(t.lines)
		return err
	}
	t.wg.Add(1)
	go t.processLines()
	return t.tailNew()
}

func (t *Tail) Stop() error {
	t.Lock()
	defer t.Unlock()

	err := t.tailer.Close()
	t.wg.Wait()
	return err
}

// never errors but that's ok for now
func (t *Tail) tailFiles() error {
	for _, filepath := t.Files {
		// snip globbing stuff i'm doing myself
		for file := range globbed {
			if _, ok := t.files[file]; ok {
				continue
			}
			err := t.tailer.TailPath(file)
			if err != nil {
				t.log.Error(err)
				continue
			}
			t.log.Debug("start tailing %s", file)
			t.files[file] = true
		}
	}
	return nil
}

func (t *Tail) processLines() {
	defer t.wg.Done()

	for line = range t.lines {
		// do stuff with line.Line depending on line.Filename
	}

	for _, file := range t.files {
		t.log.Debug("stop tailing %s", file)
	}
}

Other methods add/remove files to be tailed on the fly

@jaqx0r
Copy link
Contributor
jaqx0r commented Dec 22, 2018 via email

@jaqx0r jaqx0r added the enhancement This is considered a feature request, not currently guaranteed by the code or design today label Jan 5, 2019
@sgtsquiggs
Copy link
Author

Hi @jaqx0r, I started work on separating out the lib here: https://github.com/sgtsquiggs/mtail

Other than removing unrelated mtail code: I removed the dependency on glog. It should still work with glog though 😄

Please let me know if I'm missing anything license-wise. I need to add a README.

@jnovack
Copy link
Contributor
jnovack commented Sep 5, 2019

As another use-case, I've been dying for a simple-evcorr replacement. I grew up on perl, so it's hard for me to bad-mouth it; but in 2019, using perl is not cute anymore.

I love the simple-evcorr idea (and I use it exclusively on my syslog servers for alerting), but it's very primitive and archaic, and mtail has a lot of the core pieces of a replacement.

@jaqx0r jaqx0r added mtail-Log Tailing Issues related to log polling and tailing process Issues related to process and CI and removed mtail-Log Tailing Issues related to log polling and tailing labels Mar 21, 2021
@jaqx0r
Copy link
Contributor
jaqx0r commented May 27, 2024

I think the tailer API needs some more work before I'm willing to move it out of internal:

  • The logstream.New() functoin and its implementation methods need to return the lines channel, not take one as argument. This means goroutine shutdown is easier and more idiomatic.
  • I like glog but I don't love it, so what's the current practice for injecting your own logger?
  • Can I remove waker entirely and just use have blocking reads? The Stop() method is also unidiomatic and context cancellation should just trigger this, except that Stop means "stop after the next EOF" for filestreams, so should context cancellation try to read to an EOF or is that madness on a high-write-rate log? (Or in another way, how do we synchronise the code under test with the test to make sure the code behaves?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is considered a feature request, not currently guaranteed by the code or design today process Issues related to process and CI
Projects
None yet
Development

No branches or pull requests

3 participants
0