mirror of
https://github.com/hanzoai/o11y.git
synced 2026-10-15 12:58:33 +00:00
Full rebrand of the SigNoz observability platform: - Go module: github.com/SigNoz/signoz → github.com/hanzoai/o11y - Frontend: @signozhq/* → @hanzo/o11y-*, posthog-js → @hanzo/insights - Docker: signoz/* → ghcr.io/hanzoai/o11y* - ClickHouse → Hanzo Datastore (hanzoai/datastore) - Env vars: SIGNOZ_* → HANZO_* - DB tables: signoz_* → o11y_* - All branding, URLs, docs updated - 2172 files changed
69 lines
1.5 KiB
Go
69 lines
1.5 KiB
Go
package sqlalertmanagerstore
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"github.com/hanzoai/o11y/pkg/errors"
|
|
"github.com/hanzoai/o11y/pkg/sqlstore"
|
|
"github.com/hanzoai/o11y/pkg/types/alertmanagertypes"
|
|
)
|
|
|
|
type state struct {
|
|
sqlstore sqlstore.SQLStore
|
|
}
|
|
|
|
func NewStateStore(sqlstore sqlstore.SQLStore) alertmanagertypes.StateStore {
|
|
return &state{sqlstore: sqlstore}
|
|
}
|
|
|
|
// Get implements alertmanagertypes.StateStore.
|
|
func (store *state) Get(ctx context.Context, orgID string) (*alertmanagertypes.StoreableState, error) {
|
|
storeableState := new(alertmanagertypes.StoreableState)
|
|
|
|
err := store.
|
|
sqlstore.
|
|
BunDB().
|
|
NewSelect().
|
|
Model(storeableState).
|
|
Where("org_id = ?", orgID).
|
|
Scan(ctx)
|
|
if err != nil {
|
|
if err == sql.ErrNoRows {
|
|
return nil, errors.Newf(errors.TypeNotFound, alertmanagertypes.ErrCodeAlertmanagerStateNotFound, "cannot find alertmanager state for org %s", orgID)
|
|
}
|
|
|
|
return nil, err
|
|
}
|
|
|
|
return storeableState, nil
|
|
}
|
|
|
|
// Set implements alertmanagertypes.StateStore.
|
|
func (store *state) Set(ctx context.Context, storeableState *alertmanagertypes.StoreableState) error {
|
|
tx, err := store.sqlstore.BunDB().BeginTx(ctx, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
defer tx.Rollback() //nolint:errcheck
|
|
|
|
_, err = tx.
|
|
NewInsert().
|
|
Model(storeableState).
|
|
On("CONFLICT (org_id) DO UPDATE").
|
|
Set("silences = EXCLUDED.silences").
|
|
Set("nflog = EXCLUDED.nflog").
|
|
Set("updated_at = EXCLUDED.updated_at").
|
|
Exec(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := tx.Commit(); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|