Documentation ¶
Index ¶
- Constants
- func ElasticHandler(logger *slog.Logger, w http.ResponseWriter, r *http.Request, ...)
- func ListenAndServe(ctx context.Context, addr string, h http.Handler) error
- func RequireAnyScope(ctx context.Context, scopes ...string) (*elephantine.AuthInfo, error)
- func RunIndex(ctx context.Context, p Parameters) error
- type ACLEntry
- type ActiveIndexGetter
- type BooleanQuery
- type ClusterAuth
- type ClusterGetter
- type Coordinator
- type CoordinatorOptions
- type Document
- func (d *Document) AddField(name string, t FieldType, value string)
- func (d *Document) AddInteger(name string, value int64)
- func (d *Document) AddTime(name string, value time.Time)
- func (d *Document) Mappings() Mappings
- func (d *Document) SetField(name string, t FieldType, values ...string)
- func (d *Document) Values() map[string][]string
- type DocumentSource
- type DocumentState
- type ElasticError
- type ElasticErrorResponse
- type ElasticErrorType
- type ElasticProxy
- type ElasticQuery
- type ElasticSearchRequest
- type Field
- type FieldType
- type IdsQuery
- type Indexer
- type IndexerOptions
- type Language
- type LanguageConfig
- type ManagementService
- func (s *ManagementService) DeleteCluster(ctx context.Context, req *index.DeleteClusterRequest) (*index.DeleteClusterResponse, error)
- func (s *ManagementService) DeleteIndexSet(ctx context.Context, req *index.DeleteIndexSetRequest) (*index.DeleteIndexSetResponse, error)
- func (s *ManagementService) ListClusters(ctx context.Context, _ *index.ListClustersRequest) (*index.ListClustersResponse, error)
- func (s *ManagementService) ListIndexSets(ctx context.Context, req *index.ListIndexSetsRequest) (*index.ListIndexSetsResponse, error)
- func (s *ManagementService) PartialReindex(ctx context.Context, _ *index.PartialReindexRequest) (*index.PartialReindexResponse, error)
- func (s *ManagementService) RegisterCluster(ctx context.Context, req *index.RegisterClusterRequest) (*index.RegisterClusterResponse, error)
- func (s *ManagementService) Reindex(ctx context.Context, req *index.ReindexRequest) (*index.ReindexResponse, error)
- func (s *ManagementService) SetIndexSetStatus(ctx context.Context, req *index.SetIndexSetStatusRequest) (*index.SetIndexSetStatusResponse, error)
- type Mapping
- type MappingChange
- type MappingChanges
- type Mappings
- type Metrics
- type Notification
- type NotifyChannel
- type OSClientProvider
- type OpenSearchClientFunc
- type OpensearchSettings
- type Parameters
- type RawSearchRequest
- type SchemaLoader
- type SearchResponseBody
- type ServerOptions
- type Status
- type ValidatorSource
- type ValueCollector
Constants ¶
const IndexerStopTimeout = 10 * time.Second
const (
ScopeIndexAdmin = "index_admin"
)
Variables ¶
This section is empty.
Functions ¶
func ElasticHandler ¶
func ListenAndServe ¶ added in v0.3.0
func RequireAnyScope ¶ added in v0.3.0
Types ¶
type ActiveIndexGetter ¶ added in v0.3.0
type ActiveIndexGetter interface {
GetActiveIndex() (*opensearch.Client, string)
}
type BooleanQuery ¶
type BooleanQuery struct { Must []json.RawMessage `json:"must,omitempty"` MustNot []ElasticQuery `json:"must_not,omitempty"` Should []ElasticQuery `json:"should,omitempty"` Filter []ElasticQuery `json:"filter,omitempty"` }
type ClusterAuth ¶ added in v0.3.0
type ClusterAuth struct {
IAM bool
}
type ClusterGetter ¶ added in v0.3.0
type Coordinator ¶ added in v0.3.0
type Coordinator struct {
// contains filtered or unexported fields
}
func NewCoordinator ¶ added in v0.3.0
func NewCoordinator( db *pgxpool.Pool, opt CoordinatorOptions, ) (*Coordinator, error)
func (*Coordinator) EnsureDefaultIndexSet ¶ added in v0.3.0
func (c *Coordinator) EnsureDefaultIndexSet( ctx context.Context, defaultClusterURL string, clusterAuth ClusterAuth, ) error
Ensure that we have a default cluster and index set. Starts with an ACCESS EXCLUSIVE lock on the cluster table, so only one instance will be running this check at any given time.
func (*Coordinator) GetActiveIndex ¶ added in v0.3.0
func (c *Coordinator) GetActiveIndex() (*opensearch.Client, string)
GetActiveIndex the name of the currently active index set, and an OpenSearch client that can be used to access it.
func (*Coordinator) Run ¶ added in v0.3.0
func (c *Coordinator) Run(ctx context.Context) error
Run the coordinator. A coordinator can only run once.
func (*Coordinator) Stop ¶ added in v0.3.0
func (c *Coordinator) Stop(timeout time.Duration)
Stop the coordinator. Blocks until it has stopped or the timeout has been reached.
type CoordinatorOptions ¶ added in v0.3.0
type CoordinatorOptions struct { Logger *slog.Logger Metrics *Metrics Documents repository.Documents ClientGetter OpenSearchClientFunc Validator ValidatorSource DefaultLanguage string }
type Document ¶
func BuildDocument ¶
func BuildDocument(validator *revisor.Validator, state *DocumentState) *Document
func NewDocument ¶
func NewDocument() *Document
func (*Document) AddInteger ¶
type DocumentSource ¶ added in v0.2.0
type DocumentSource struct {
DocumentLanguage []string `json:"document.language"`
}
Some well-known field names used by the indexer.
type DocumentState ¶
type DocumentState struct { Created time.Time `json:"created"` Modified time.Time `json:"modified"` CurrentVersion int64 `json:"current_version"` ACL []ACLEntry `json:"acl"` Heads map[string]Status `json:"heads"` Document newsdoc.Document `json:"document"` }
DocumentState is the full state that we want to index.
type ElasticError ¶
type ElasticError struct { Reason string `json:"reason"` Details string `json:"details"` Type ElasticErrorType `json:"type"` }
type ElasticErrorResponse ¶
type ElasticErrorResponse struct { ErrorInfo ElasticError `json:"error"` Status int `json:"status"` }
func ElasticErrorf ¶
func ElasticErrorf(t ElasticErrorType, format string, a ...any) ElasticErrorResponse
func (ElasticErrorResponse) Error ¶
func (er ElasticErrorResponse) Error() string
type ElasticErrorType ¶
type ElasticErrorType string
const ( ErrorTypeAccessDenied ElasticErrorType = "elephant.AccessDenied" ErrorTypeInternal ElasticErrorType = "elephant.InternalError" ErrorTypeBadRequest ElasticErrorType = "elephant.BadRequest" ErrorTypeNotFound ElasticErrorType = "elephant.NotFound" )
func (ElasticErrorType) Reason ¶
func (et ElasticErrorType) Reason() string
func (ElasticErrorType) StatusCode ¶
func (et ElasticErrorType) StatusCode() int
type ElasticProxy ¶
type ElasticProxy struct {
// contains filtered or unexported fields
}
func NewElasticProxy ¶
func NewElasticProxy( logger *slog.Logger, active ActiveIndexGetter, publicJWTKey *ecdsa.PublicKey, ) *ElasticProxy
func (*ElasticProxy) ServeHTTP ¶
func (ep *ElasticProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)
type ElasticQuery ¶
type ElasticQuery struct { Bool *BooleanQuery `json:"bool,omitempty"` Term map[string]string `json:"term,omitempty"` Ids *IdsQuery `json:"ids,omitempty"` }
type ElasticSearchRequest ¶
type ElasticSearchRequest struct { Query ElasticQuery `json:"query"` Fields json.RawMessage `json:"fields,omitempty"` Sort json.RawMessage `json:"sort,omitempty"` Source *bool `json:"_source,omitempty"` From *int `json:"from,omitempty"` Size *int `json:"size,omitempty"` }
type Indexer ¶
type Indexer struct {
// contains filtered or unexported fields
}
Indexer takes care of indexing to a named set of indexes in a cluster.
func NewIndexer ¶
func NewIndexer(ctx context.Context, opts IndexerOptions) (*Indexer, error)
type IndexerOptions ¶
type IndexerOptions struct { Logger *slog.Logger SetName string Database *pgxpool.Pool Client *opensearch.Client Documents repository.Documents Validator ValidatorSource Metrics *Metrics DefaultLanguage string }
type LanguageConfig ¶
type LanguageConfig struct { NameSuffix string Language string Settings OpensearchSettings }
func GetLanguageConfig ¶
func GetLanguageConfig(code string, defaultLanguage string) (LanguageConfig, error)
type ManagementService ¶ added in v0.3.0
type ManagementService struct {
// contains filtered or unexported fields
}
func NewManagementService ¶ added in v0.3.0
func (*ManagementService) DeleteCluster ¶ added in v0.3.0
func (s *ManagementService) DeleteCluster( ctx context.Context, req *index.DeleteClusterRequest, ) (*index.DeleteClusterResponse, error)
DeleteCluster implements index.Management.
func (*ManagementService) DeleteIndexSet ¶ added in v0.3.0
func (s *ManagementService) DeleteIndexSet( ctx context.Context, req *index.DeleteIndexSetRequest, ) (*index.DeleteIndexSetResponse, error)
DeleteIndexSet implements index.Management.
func (*ManagementService) ListClusters ¶ added in v0.3.0
func (s *ManagementService) ListClusters( ctx context.Context, _ *index.ListClustersRequest, ) (*index.ListClustersResponse, error)
ListClusters implements index.Management.
func (*ManagementService) ListIndexSets ¶ added in v0.3.0
func (s *ManagementService) ListIndexSets( ctx context.Context, req *index.ListIndexSetsRequest, ) (*index.ListIndexSetsResponse, error)
ListIndexSets implements index.Management.
func (*ManagementService) PartialReindex ¶ added in v0.3.0
func (s *ManagementService) PartialReindex( ctx context.Context, _ *index.PartialReindexRequest, ) (*index.PartialReindexResponse, error)
PartialReindex implements index.Management.
func (*ManagementService) RegisterCluster ¶ added in v0.3.0
func (s *ManagementService) RegisterCluster( ctx context.Context, req *index.RegisterClusterRequest, ) (*index.RegisterClusterResponse, error)
RegisterCluster implements index.Management.
func (*ManagementService) Reindex ¶ added in v0.3.0
func (s *ManagementService) Reindex( ctx context.Context, req *index.ReindexRequest, ) (*index.ReindexResponse, error)
Reindex implements index.Management.
func (*ManagementService) SetIndexSetStatus ¶ added in v0.3.0
func (s *ManagementService) SetIndexSetStatus( ctx context.Context, req *index.SetIndexSetStatusRequest, ) (*index.SetIndexSetStatusResponse, error)
SetIndexSetStatus implements index.Management.
type MappingChange ¶
type MappingChanges ¶
type MappingChanges map[string]MappingChange
func (MappingChanges) HasNew ¶
func (mc MappingChanges) HasNew() bool
func (MappingChanges) Superset ¶
func (mc MappingChanges) Superset(mappings Mappings) Mappings
type Mappings ¶
func NewMappings ¶
func NewMappings() Mappings
func (*Mappings) ChangesFrom ¶
func (m *Mappings) ChangesFrom(mappings Mappings) MappingChanges
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
func NewMetrics ¶
func NewMetrics(reg prometheus.Registerer) (*Metrics, error)
type Notification ¶ added in v0.3.0
type Notification struct { Type NotifyChannel Name string }
type NotifyChannel ¶ added in v0.3.0
type NotifyChannel string
const (
NotifyIndexStatusChange NotifyChannel = "index_status_change"
)
type OSClientProvider ¶ added in v0.3.0
type OSClientProvider struct {
// contains filtered or unexported fields
}
func NewOSClientProvider ¶ added in v0.3.0
func NewOSClientProvider(clusters ClusterGetter) *OSClientProvider
func (*OSClientProvider) GetClientForCluster ¶ added in v0.3.0
func (o *OSClientProvider) GetClientForCluster( ctx context.Context, cluster string, ) (*opensearch.Client, error)
type OpenSearchClientFunc ¶ added in v0.3.0
type OpensearchSettings ¶
type OpensearchSettings struct { Settings struct { Analysis struct { Analyzer struct { Default struct { Type string `json:"type"` } `json:"default"` } `json:"analyzer"` } `json:"analysis"` } `json:"settings"` }
type Parameters ¶ added in v0.3.0
type Parameters struct { Addr string ProfileAddr string Logger *slog.Logger Database *pgxpool.Pool DefaultCluster string ClusterAuth ClusterAuth Client OpenSearchClientFunc Documents repository.Documents Validator ValidatorSource Metrics *Metrics DefaultLanguage string NoIndexer bool PublicJWTKey *ecdsa.PublicKey }
type RawSearchRequest ¶
type RawSearchRequest struct { Query json.RawMessage `json:"query"` Fields json.RawMessage `json:"fields"` Sort json.RawMessage `json:"sort"` Source *bool `json:"_source,omitempty"` From *int `json:"from,omitempty"` Size *int `json:"size,omitempty"` }
type SchemaLoader ¶
type SchemaLoader struct {
// contains filtered or unexported fields
}
func NewSchemaLoader ¶
func NewSchemaLoader( ctx context.Context, logger *slog.Logger, client repository.Schemas, ) (*SchemaLoader, error)
func (*SchemaLoader) GetValidator ¶
func (sl *SchemaLoader) GetValidator() *revisor.Validator
type SearchResponseBody ¶ added in v0.2.0
type SearchResponseBody struct { Hits struct { Hits []struct { ID string `json:"_id"` Index string `json:"_index"` Source DocumentSource `json:"_source"` } `json:"hits"` } `json:"hits"` }
type ServerOptions ¶ added in v0.3.0
type ServerOptions struct { Hooks *twirp.ServerHooks AuthMiddleware func( w http.ResponseWriter, r *http.Request, next http.Handler, ) error }
func (*ServerOptions) SetJWTValidation ¶ added in v0.3.0
func (so *ServerOptions) SetJWTValidation(jwtKey *ecdsa.PublicKey)
type ValidatorSource ¶
type ValueCollector ¶
type ValueCollector struct {
// contains filtered or unexported fields
}
func NewValueCollector ¶
func NewValueCollector() *ValueCollector
func (*ValueCollector) CollectValue ¶
func (c *ValueCollector) CollectValue(a revisor.ValueAnnotation)
func (*ValueCollector) Values ¶
func (c *ValueCollector) Values() []revisor.ValueAnnotation
func (*ValueCollector) With ¶
func (c *ValueCollector) With(ref revisor.EntityRef) revisor.ValueCollector