streaming

package
v0.0.0-...-b2e0f1d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DocumentMatchLimit is when we found too many matches in a document, so
	// we stopped searching it.
	DocumentMatchLimit SkippedReason = "document-match-limit"
	// ShardMatchLimit is when we found too many matches in a
	// shard/repository, so we stopped searching it.
	ShardMatchLimit = "shard-match-limit"
	// RepositoryLimit is when we did not search a repository because the set
	// of repositories to search was too large.
	RepositoryLimit = "repository-limit"
	// ShardTimeout is when we ran out of time before searching a
	// shard/repository.
	ShardTimeout = "shard-timeout"
	// RepositoryCloning is when we could not search a repository because it
	// is not cloned.
	RepositoryCloning = "repository-cloning"
	// RepositoryMissing is when we could not search a repository because it
	// is not cloned and we failed to find it on the remote code host.
	RepositoryMissing = "repository-missing"
	// ExcludedFork is when we did not search a repository because it is a
	// fork.
	ExcludedFork = "repository-fork"
	// ExcludedArchive is when we did not search a repository because it is
	// archived.
	ExcludedArchive = "excluded-archive"
)

Variables

This section is empty.

Functions

func NewRequest

func NewRequest(baseURL string, query string) (*http.Request, error)

NewRequest returns an http.Request against the streaming API for query.

func Search(query string, opts Opts, client api.Client, decoder Decoder) error

Search calls the streaming search endpoint and uses decoder to decode the response body.

Types

type ChunkMatch

type ChunkMatch struct {
	Content      string   `json:"content"`
	ContentStart Location `json:"contentStart"`
	Ranges       []Range  `json:"ranges"`
}

type Decoder

type Decoder struct {
	OnProgress func(*Progress)
	OnMatches  func([]EventMatch)
	OnFilters  func([]*EventFilter)
	OnAlert    func(*EventAlert)
	OnError    func(*EventError)
	OnUnknown  func(event, data []byte)
}

Decoder decodes streaming events from a Server Sent Event stream. We only support streams which are generated by Sourcegraph. IE this is not a fully compliant Server Sent Events decoder.

func (Decoder) ReadAll

func (rr Decoder) ReadAll(r io.Reader) error

type EventAlert

type EventAlert struct {
	Title           string          `json:"title"`
	Description     string          `json:"description,omitempty"`
	ProposedQueries []ProposedQuery `json:"proposedQueries"`
}

EventAlert is GQL.SearchAlert. It replaces when sent to match existing behaviour.

type EventCommitMatch

type EventCommitMatch struct {
	// Type is always CommitMatchType. Included here for marshalling.
	Type MatchType `json:"type"`

	Icon    string `json:"icon"`
	Label   string `json:"label"`
	URL     string `json:"url"`
	Detail  string `json:"detail"`
	Content string `json:"content"`
	// [line, character, length]
	Ranges [][3]int32 `json:"ranges"`
}

EventCommitMatch is the generic results interface from GQL. There is a lot of potential data that may be useful here, and some thought needs to be put into what is actually useful in a commit result / or if we should have a "type" for that.

type EventContentMatch

type EventContentMatch struct {
	// Type is always ContentMatchType. Included here for marshalling.
	Type MatchType `json:"type"`

	Path         string       `json:"path"`
	Repository   string       `json:"repository"`
	Branches     []string     `json:"branches,omitempty"`
	Commit       string       `json:"commit,omitempty"`
	ChunkMatches []ChunkMatch `json:"chunkMatches"`
}

EventContentMatch is a subset of zoekt.FileMatch for our Event API.

type EventError

type EventError struct {
	Message string `json:"message"`
}

EventError emulates a JavaScript error with a message property as is returned when the search encounters an error.

type EventFilter

type EventFilter struct {
	Value    string `json:"value"`
	Label    string `json:"label"`
	Count    int    `json:"count"`
	LimitHit bool   `json:"limitHit"`
	Kind     string `json:"kind"`
}

EventFilter is a suggestion for a search filter. Currently has a 1-1 correspondance with the SearchFilter graphql type.

type EventLineMatch

type EventLineMatch struct {
	Line             string     `json:"line"`
	LineNumber       int32      `json:"lineNumber"`
	OffsetAndLengths [][2]int32 `json:"offsetAndLengths"`
}

EventLineMatch is a subset of zoekt.LineMatch for our Event API.

type EventMatch

type EventMatch interface {
	// contains filtered or unexported methods
}

EventMatch is an interface which only the top level match event types implement. Use this for your results slice rather than interface{}.

type EventPathMatch

type EventPathMatch struct {
	// Type is always PathMatchType. Included here for marshalling.
	Type MatchType `json:"type"`

	Path       string   `json:"path"`
	Repository string   `json:"repository"`
	Branches   []string `json:"branches,omitempty"`
	Commit     string   `json:"commit,omitempty"`
}

EventPathMatch is a subset of zoekt.FileMatch for our Event API.

type EventRepoMatch

type EventRepoMatch struct {
	// Type is always RepoMatchType. Included here for marshalling.
	Type MatchType `json:"type"`

	Repository string   `json:"repository"`
	Branches   []string `json:"branches,omitempty"`
}

EventRepoMatch is a subset of zoekt.FileMatch for our Event API.

type EventSymbolMatch

type EventSymbolMatch struct {
	// Type is always SymbolMatchType. Included here for marshalling.
	Type MatchType `json:"type"`

	Path       string   `json:"path"`
	Repository string   `json:"repository"`
	Branches   []string `json:"branches,omitempty"`
	Commit     string   `json:"commit,omitempty"`

	Symbols []Symbol `json:"symbols"`
}

EventSymbolMatch is EventFileMatch but with Symbols instead of LineMatches

type Location

type Location struct {
	Offset int `json:"offset"`
	Line   int `json:"line"`
	Column int `json:"column"`
}

type MatchType

type MatchType int
const (
	ContentMatchType MatchType = iota
	RepoMatchType
	SymbolMatchType
	CommitMatchType
	PathMatchType
)

func (MatchType) MarshalJSON

func (t MatchType) MarshalJSON() ([]byte, error)

func (*MatchType) UnmarshalJSON

func (t *MatchType) UnmarshalJSON(b []byte) error

type Opts

type Opts struct {
	Display int
	Trace   bool
	Json    bool
}

Opts contains the search options supported by Search.

type Progress

type Progress struct {
	// Done is true if this is a final progress event.
	Done bool `json:"done"`

	// RepositoriesCount is the number of repositories being searched. It is
	// non-nil once the set of repositories has been resolved.
	RepositoriesCount *int `json:"repositoriesCount,omitempty"`

	// MatchCount is number of non-overlapping matches. If skipped is
	// non-empty, then this is a lower bound.
	MatchCount int `json:"matchCount"`

	// DurationMs is the wall clock time in milliseconds for this search.
	DurationMs int `json:"durationMs"`

	// Skipped is a description of shards or documents that were skipped. This
	// has a deterministic ordering. More important reasons will be listed
	// first. If a search is repeated, the final skipped list will be the
	// same.  However, within a search stream when a new skipped reason is
	// found, it may appear anywhere in the list.
	Skipped []Skipped `json:"skipped"`
}

Progress is an aggregate type representing a progress update.

type ProposedQuery

type ProposedQuery struct {
	Description string `json:"description,omitempty"`
	Query       string `json:"query"`
}

ProposedQuery is a suggested query to run when we emit an alert.

type Range

type Range struct {
	Start Location `json:"start"`
	End   Location `json:"end"`
}

type Skipped

type Skipped struct {
	// Reason is why a document/shard/repository was skipped. We group counts
	// by reason. eg ShardTimeout
	Reason SkippedReason `json:"reason"`
	// Title is a short message. eg "1,200 timed out".
	Title string `json:"title"`
	// Message is a message to show the user. Usually includes information
	// explaining the reason, count as well as a sample of the missing items.
	Message  string          `json:"message"`
	Severity SkippedSeverity `json:"severity"`
	// Suggested is a query expression to remedy the skip. eg "archived:yes".
	Suggested *SkippedSuggested `json:"suggested,omitempty"`
}

Skipped is a description of shards or documents that were skipped.

type SkippedReason

type SkippedReason string

SkippedReason is an enum for Skipped.Reason.

type SkippedSeverity

type SkippedSeverity string

SkippedSeverity is an enum for Skipped.Severity.

const (
	SeverityInfo SkippedSeverity = "info"
	SeverityWarn SkippedSeverity = "warn"
)

type SkippedSuggested

type SkippedSuggested struct {
	Title           string `json:"title"`
	QueryExpression string `json:"queryExpression"`
}

SkippedSuggested is a query to suggest to the user to resolve the reason for skipping.

type Symbol

type Symbol struct {
	URL           string `json:"url"`
	Name          string `json:"name"`
	ContainerName string `json:"containerName"`
	Kind          string `json:"kind"`
}

type Writer

type Writer struct {
	StatHook func(WriterStat)
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(w http.ResponseWriter) (*Writer, error)

func (*Writer) Event

func (e *Writer) Event(event string, data interface{}) error

Event writes event with data json marshalled.

func (*Writer) EventBytes

func (e *Writer) EventBytes(event string, dataLine []byte) (err error)

EventBytes writes dataLine as an event. dataLine is not allowed to contain a newline.

type WriterStat

type WriterStat struct {
	Event    string
	Bytes    int
	Duration time.Duration
	Error    error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL