opensearch

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractLogType

func ExtractLogType(logType string) string

ExtractLogType determines the log type from query parameters or defaults to RUNTIME

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps the OpenSearch client with logging and configuration

func NewClient

func NewClient(cfg *config.OpenSearchConfig, logger *slog.Logger) (*Client, error)

NewClient creates a new OpenSearch client with the provided configuration

func (*Client) GetIndexMapping

func (c *Client) GetIndexMapping(ctx context.Context, index string) (*MappingResponse, error)

GetIndexMapping retrieves the mapping for a specific index

func (*Client) HealthCheck

func (c *Client) HealthCheck(ctx context.Context) error

HealthCheck performs a basic health check on the OpenSearch cluster

func (*Client) Search

func (c *Client) Search(ctx context.Context, indices []string, query map[string]interface{}) (*SearchResponse, error)

Search executes a search request against OpenSearch

type ComponentQueryParams

type ComponentQueryParams struct {
	QueryParams
	BuildID   string `json:"buildId,omitempty"`
	BuildUUID string `json:"buildUuid,omitempty"`
}

ComponentQueryParams holds component-specific query parameters

type ComponentTracesRequestParams added in v0.4.0

type ComponentTracesRequestParams struct {
	EndTime     string `json:"endTime"`
	Limit       int    `json:"limit,omitempty"`
	ServiceName string `json:"serviceName"`
	SortOrder   string `json:"sortOrder,omitempty"`
	StartTime   string `json:"startTime"`
}

ComponentTracesRequestParams holds request body parameters for component traces

type FieldMapping

type FieldMapping struct {
	Type       string                  `json:"type"`
	Fields     map[string]FieldMapping `json:"fields,omitempty"`
	Properties map[string]FieldMapping `json:"properties,omitempty"`
}

FieldMapping represents the mapping for a single field

type GatewayQueryParams

type GatewayQueryParams struct {
	QueryParams
	OrganizationID    string            `json:"organizationId"`
	APIIDToVersionMap map[string]string `json:"apiIdToVersionMap"`
	GatewayVHosts     []string          `json:"gatewayVHosts"`
}

GatewayQueryParams holds gateway-specific query parameters

type Hit

type Hit struct {
	Source map[string]interface{} `json:"_source"`
	Score  *float64               `json:"_score"`
}

Hit represents a single search result hit

type IndexMapping

type IndexMapping struct {
	Mappings struct {
		Properties map[string]FieldMapping `json:"properties"`
	} `json:"mappings"`
}

IndexMapping represents the mapping for a single index

type LogEntry

type LogEntry struct {
	Timestamp     time.Time         `json:"timestamp"`
	Log           string            `json:"log"`
	LogLevel      string            `json:"logLevel"`
	ComponentID   string            `json:"componentId"`
	EnvironmentID string            `json:"environmentId"`
	ProjectID     string            `json:"projectId"`
	Version       string            `json:"version"`
	VersionID     string            `json:"versionId"`
	Namespace     string            `json:"namespace"`
	PodID         string            `json:"podId"`
	ContainerName string            `json:"containerName"`
	Labels        map[string]string `json:"labels"`
}

LogEntry represents a parsed log entry from OpenSearch

func ParseLogEntry

func ParseLogEntry(hit Hit) LogEntry

ParseLogEntry converts a search hit to a LogEntry struct

type MappingResponse

type MappingResponse struct {
	Mappings map[string]IndexMapping `json:",inline"`
}

MappingResponse represents the response from an index mapping query

type QueryBuilder

type QueryBuilder struct {
	// contains filtered or unexported fields
}

QueryBuilder provides methods to build OpenSearch queries

func NewQueryBuilder

func NewQueryBuilder(indexPrefix string) *QueryBuilder

NewQueryBuilder creates a new query builder with the given index prefix

func (*QueryBuilder) BuildComponentLogsQuery

func (qb *QueryBuilder) BuildComponentLogsQuery(params ComponentQueryParams) map[string]interface{}

BuildComponentLogsQuery builds a query for component logs with wildcard search

func (*QueryBuilder) BuildComponentTracesQuery added in v0.4.0

func (qb *QueryBuilder) BuildComponentTracesQuery(params ComponentTracesRequestParams) map[string]interface{}

func (*QueryBuilder) BuildGatewayLogsQuery

func (qb *QueryBuilder) BuildGatewayLogsQuery(params GatewayQueryParams) map[string]interface{}

BuildGatewayLogsQuery builds a query for gateway logs with wildcard search

func (*QueryBuilder) BuildOrganizationLogsQuery

func (qb *QueryBuilder) BuildOrganizationLogsQuery(params QueryParams, podLabels map[string]string) map[string]interface{}

BuildOrganizationLogsQuery builds a query for organization logs with wildcard search

func (*QueryBuilder) BuildProjectLogsQuery

func (qb *QueryBuilder) BuildProjectLogsQuery(params QueryParams, componentIDs []string) map[string]interface{}

BuildProjectLogsQuery builds a query for project logs with wildcard search

func (*QueryBuilder) CheckQueryVersion

func (qb *QueryBuilder) CheckQueryVersion(mapping *MappingResponse, indexName string) string

CheckQueryVersion determines if the index supports V2 wildcard queries

func (*QueryBuilder) GenerateIndices

func (qb *QueryBuilder) GenerateIndices(startTime, endTime string) ([]string, error)

GenerateIndices generates the list of indices to search based on time range

type QueryParams

type QueryParams struct {
	StartTime      string   `json:"startTime"`
	EndTime        string   `json:"endTime"`
	SearchPhrase   string   `json:"searchPhrase"`
	LogLevels      []string `json:"logLevels"`
	Limit          int      `json:"limit"`
	SortOrder      string   `json:"sortOrder"`
	ComponentID    string   `json:"componentId,omitempty"`
	EnvironmentID  string   `json:"environmentId,omitempty"`
	ProjectID      string   `json:"projectId,omitempty"`
	OrganizationID string   `json:"organizationId,omitempty"`
	Namespace      string   `json:"namespace,omitempty"`
	Versions       []string `json:"versions,omitempty"`
	VersionIDs     []string `json:"versionIds,omitempty"`
	LogType        string   `json:"logType,omitempty"`
}

QueryParams holds common query parameters

type SearchResponse

type SearchResponse struct {
	Hits struct {
		Total struct {
			Value    int    `json:"value"`
			Relation string `json:"relation"`
		} `json:"total"`
		Hits []Hit `json:"hits"`
	} `json:"hits"`
	Took     int  `json:"took"`
	TimedOut bool `json:"timed_out"`
}

SearchResponse represents the response from an OpenSearch search query

type Span added in v0.4.0

type Span struct {
	DurationInNanos int64     `json:"durationInNanos"`
	EndTime         time.Time `json:"endTime"`
	Name            string    `json:"name"`
	SpanID          string    `json:"spanId"`
	StartTime       time.Time `json:"startTime"`
	TraceID         string    `json:"traceId"`
}

Span represents a parsed span entry from OpenSearch

func ParseSpanEntry added in v0.4.0

func ParseSpanEntry(hit Hit) Span

ParseSpanEntry converts a search hit of a span to a SpanEntry struct

type TraceResponse added in v0.4.0

type TraceResponse struct {
	Spans      []Span `json:"spans"`
	TotalCount int    `json:"totalCount"`
	Took       int    `json:"tookMs"`
}

TraceResponse represents the response structure for trace queries

Jump to

Keyboard shortcuts

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