github.com/qubitproducts/logspray@v0.2.14/sources/logsource.go (about)

     1  // Copyright 2016 Qubit Digital Ltd.
     2  // Licensed under the Apache License, Version 2.0 (the "License");
     3  // you may not use this file except in compliance with the License.
     4  // You may obtain a copy of the License at
     5  //
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  // Package logspray is a collection of tools for streaming and indexing
    14  // large volumes of dynamic logs.
    15  
    16  package sources
    17  
    18  import (
    19  	"context"
    20  
    21  	"github.com/QubitProducts/logspray/proto/logspray"
    22  )
    23  
    24  // Sourcer watches some arbitrary potential source of multiple log streams.
    25  // Each time the Updater spots a new stream, ReadTarget is called to read
    26  // message from that stream.
    27  type Sourcer interface {
    28  	// Updater implementation required to find new streams.
    29  	Updater
    30  
    31  	// ReadTarget is called in response to a new target being found by the updater
    32  	// The supplied context will be cancel'ed when the updater sees the source go
    33  	// away. FromStart indicates whther you should read the stream from the
    34  	// beginning, or the current position.
    35  	ReadTarget(ctx context.Context, id string, FromStart bool) (MessageReader, error)
    36  }
    37  
    38  // MessageReader is used to Read a message from a source.
    39  type MessageReader interface {
    40  	MessageRead(ctx context.Context) (*logspray.Message, error)
    41  }
    42  
    43  // Updaer is used to watch for changes to a set of potential log sources. The
    44  // furst call to Next should return any pre-existing log sources. Subsequent
    45  // calls should describe changes to that set.
    46  type Updater interface {
    47  	Next(context.Context) ([]*Update, error)
    48  }