Documentation
¶
Overview ¶
Package pgstore implements the userstore.Store interface using PostgreSQL
Package pgstore provides PostgreSQL storage implementation for GoSight process data.
This file implements process-specific storage operations including:
- Bulk insertion of process snapshots for efficient batch processing
- Individual process snapshot and detail insertion
- Flexible querying with filtering, sorting, and pagination
- JSON handling for process labels and metadata
The storage model separates process snapshots (point-in-time system state) from individual process details to optimize for both write performance and query flexibility. Process snapshots contain host metadata and timing information, while process_info records contain the detailed process data.
Index ¶
- type PGDataStore
- func (s *PGDataStore) Close() error
- func (s *PGDataStore) DeleteNetworkDeviceByID(ctx context.Context, id string) error
- func (s *PGDataStore) DeleteTag(ctx context.Context, endpointID, key string) error
- func (s *PGDataStore) GetAgentByHostname(ctx context.Context, hostname string) (*model.Agent, error)
- func (s *PGDataStore) GetAgentByID(ctx context.Context, id string) (*model.Agent, error)
- func (s *PGDataStore) GetAllNetworkDevices(ctx context.Context) ([]*model.NetworkDevice, error)
- func (s *PGDataStore) GetAllTags(ctx context.Context) ([]model.Tag, error)
- func (s *PGDataStore) GetContainerByID(ctx context.Context, id string) (*model.Container, error)
- func (s *PGDataStore) GetNetworkDeviceByAddress(ctx context.Context, address string) (*model.NetworkDevice, error)
- func (s *PGDataStore) GetNetworkDevices(ctx context.Context, filter *model.NetworkDeviceFilter) ([]*model.NetworkDevice, error)
- func (s *PGDataStore) GetTags(ctx context.Context, endpointID string) (map[string]string, error)
- func (s *PGDataStore) InsertFullProcessPayload(ctx context.Context, payload *model.ProcessPayload) error
- func (s *PGDataStore) InsertProcessInfos(ctx context.Context, snapshotID int64, payload *model.ProcessPayload) error
- func (s *PGDataStore) InsertProcessSnapshot(ctx context.Context, snap *model.ProcessPayload) (int64, error)
- func (s *PGDataStore) ListAgents(ctx context.Context) ([]*model.Agent, error)
- func (s *PGDataStore) ListContainers(ctx context.Context) ([]*model.Container, error)
- func (s *PGDataStore) ListKeys(ctx context.Context) ([]string, error)
- func (s *PGDataStore) ListTags(ctx context.Context, endpointID string) (map[string]string, error)
- func (s *PGDataStore) ListValues(ctx context.Context, key string) ([]string, error)
- func (s *PGDataStore) QueryProcessInfos(ctx context.Context, filter *model.ProcessQueryFilter) ([]model.ProcessInfo, error)
- func (s *PGDataStore) SetTags(ctx context.Context, endpointID string, tags map[string]string) error
- func (s *PGDataStore) ToggleNetworkDeviceStatus(ctx context.Context, id string) error
- func (s *PGDataStore) UpsertAgent(ctx context.Context, agent *model.Agent) error
- func (s *PGDataStore) UpsertContainer(ctx context.Context, c *model.Container) error
- func (s *PGDataStore) UpsertNetworkDevice(ctx context.Context, device *model.NetworkDevice) error
- func (s *PGDataStore) Write(ctx context.Context, batches []*model.ProcessPayload) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PGDataStore ¶
type PGDataStore struct {
// contains filtered or unexported fields
}
Package pgstore implements the userstore.Store interface using PostgreSQL PGDataStore is a struct that represents a PostgreSQL data store It contains a pointer to the sql.DB object for database operations
func NewPGDataStore ¶
func NewPGDataStore(db *sql.DB) *PGDataStore
New creates a new PGDataStore instance
func (*PGDataStore) Close ¶
func (s *PGDataStore) Close() error
Close closes the database connection It checks if the db is not nil before attempting to close it
func (*PGDataStore) DeleteNetworkDeviceByID ¶
func (s *PGDataStore) DeleteNetworkDeviceByID(ctx context.Context, id string) error
DeleteNetworkDeviceByID deletes a network device by its ID
func (*PGDataStore) DeleteTag ¶
func (s *PGDataStore) DeleteTag(ctx context.Context, endpointID, key string) error
DeleteTag removes a specific tag for a given endpoint ID.
func (*PGDataStore) GetAgentByHostname ¶
func (s *PGDataStore) GetAgentByHostname(ctx context.Context, hostname string) (*model.Agent, error)
GetAgentByHostname retrieves an agent by its hostname
func (*PGDataStore) GetAgentByID ¶
GetAgentByAgentID retrieves an agent by its agent_id This is used for the agent to check in with the server
func (*PGDataStore) GetAllNetworkDevices ¶
func (s *PGDataStore) GetAllNetworkDevices(ctx context.Context) ([]*model.NetworkDevice, error)
GetNetworkDevices returns all network devices from the database
func (*PGDataStore) GetAllTags ¶
func (*PGDataStore) GetContainerByID ¶
GetContainerByID retrieves a container by its container_id
func (*PGDataStore) GetNetworkDeviceByAddress ¶
func (s *PGDataStore) GetNetworkDeviceByAddress(ctx context.Context, address string) (*model.NetworkDevice, error)
GetNetworkDeviceByAddress looks up a single NetworkDevice by its IP/hostname. Returns (nil, nil) if no matching device is found.
func (*PGDataStore) GetNetworkDevices ¶
func (s *PGDataStore) GetNetworkDevices(ctx context.Context, filter *model.NetworkDeviceFilter) ([]*model.NetworkDevice, error)
func (*PGDataStore) InsertFullProcessPayload ¶
func (s *PGDataStore) InsertFullProcessPayload(ctx context.Context, payload *model.ProcessPayload) error
InsertFullProcessPayload inserts a complete process payload into the database. This is a convenience method that combines snapshot creation with process detail insertion in a single operation. It first creates a process snapshot and then inserts all associated process information records.
func (*PGDataStore) InsertProcessInfos ¶
func (s *PGDataStore) InsertProcessInfos(ctx context.Context, snapshotID int64, payload *model.ProcessPayload) error
InsertProcessInfos inserts multiple process information records associated with a snapshot. Each process record includes detailed information such as PID, CPU/memory usage, command line, executable path, and custom labels. The insertion is performed within a transaction to ensure data consistency.
func (*PGDataStore) InsertProcessSnapshot ¶
func (s *PGDataStore) InsertProcessSnapshot(ctx context.Context, snap *model.ProcessPayload) (int64, error)
InsertProcessSnapshot inserts a new process snapshot into the database. A process snapshot represents a point-in-time capture of system process state, including metadata about the host, agent, and collection timestamp. Returns the generated snapshot ID for linking associated process details.
func (*PGDataStore) ListAgents ¶
ListAgents retrieves all agents from the database This is used for the web UI to display all agents and for the agent to check in with the server
func (*PGDataStore) ListContainers ¶
ListContainers retrieves all containers from the database This is used for the web UI to display all containers and for the agent to check in with the server
func (*PGDataStore) ListKeys ¶
func (s *PGDataStore) ListKeys(ctx context.Context) ([]string, error)
ListKeys returns all unique tag keys
func (*PGDataStore) ListValues ¶
ListValues returns all values for a given key
func (*PGDataStore) QueryProcessInfos ¶
func (s *PGDataStore) QueryProcessInfos(ctx context.Context, filter *model.ProcessQueryFilter) ([]model.ProcessInfo, error)
QueryProcessInfos retrieves process information based on the provided filter criteria. It supports filtering by endpoint, time range, resource usage thresholds, user, process IDs, and text searches in executable paths and command lines. Results can be sorted by various fields and paginated for large datasets.
func (*PGDataStore) SetTags ¶
SetTags replaces all tags for a given endpoint ID with the provided tags.
func (*PGDataStore) ToggleNetworkDeviceStatus ¶
func (s *PGDataStore) ToggleNetworkDeviceStatus(ctx context.Context, id string) error
ToggleNetworkDeviceStatus toggles the status (enabled/disabled) of a device by ID
func (*PGDataStore) UpsertAgent ¶
func (*PGDataStore) UpsertContainer ¶
UpsertContainer inserts or updates a container in the database This is used for the agent to check in with the server It also updates the last_seen field to the current time and the status field to "Running" if the container is running or "Stopped" if the container is stopped UpsertContainer inserts or updates a container in the database
func (*PGDataStore) UpsertNetworkDevice ¶
func (s *PGDataStore) UpsertNetworkDevice(ctx context.Context, device *model.NetworkDevice) error
UpsertNetworkDevice inserts a new network device or updates an existing one
func (*PGDataStore) Write ¶
func (s *PGDataStore) Write(ctx context.Context, batches []*model.ProcessPayload) error
Write implements the BufferedDataStore interface for process payloads. It performs bulk insertion of process snapshots for efficient batch processing.