mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
* Reduce piecemeal state fields * Read data directly off state instead of rule * Unify state and context into single struct * Expose contextual information to layer above setNextState * Work in terms of ContextualState and call historian in batches * Call annotations service in batches * Export format state and reason and remove workaround in unrelated test package * Add new method to annotation service for batch inserting * Fix loop variable aliasing bug caught by linter, didn't change behavior * Incl timerange on annotation tests * Insert one at a time if tags are present * Point to rule from ContextualState rather than copy fields * Build annotations and copy data prior to starting goroutine * Rename to StateTransition * Use new bulk-insert utility * Remove rule from StateTransition and pass in directly to historian * Simplify annotations logic since we have only one rule * Fix logs and context, nilcheck, simplify method name * Regenerate mock
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
package annotationsimpl
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/db"
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
"github.com/grafana/grafana/pkg/services/annotations"
|
|
"github.com/grafana/grafana/pkg/services/tag"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
)
|
|
|
|
type RepositoryImpl struct {
|
|
store store
|
|
}
|
|
|
|
func ProvideService(db db.DB, cfg *setting.Cfg, tagService tag.Service) *RepositoryImpl {
|
|
return &RepositoryImpl{
|
|
store: &xormRepositoryImpl{
|
|
cfg: cfg,
|
|
db: db,
|
|
log: log.New("annotations"),
|
|
tagService: tagService,
|
|
maximumTagsLength: cfg.AnnotationMaximumTagsLength,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (r *RepositoryImpl) Save(ctx context.Context, item *annotations.Item) error {
|
|
return r.store.Add(ctx, item)
|
|
}
|
|
|
|
// SaveMany inserts multiple annotations at once.
|
|
// It does not return IDs associated with created annotations. If you need this functionality, use the single-item Save instead.
|
|
func (r *RepositoryImpl) SaveMany(ctx context.Context, items []annotations.Item) error {
|
|
return r.store.AddMany(ctx, items)
|
|
}
|
|
|
|
func (r *RepositoryImpl) Update(ctx context.Context, item *annotations.Item) error {
|
|
return r.store.Update(ctx, item)
|
|
}
|
|
|
|
func (r *RepositoryImpl) Find(ctx context.Context, query *annotations.ItemQuery) ([]*annotations.ItemDTO, error) {
|
|
return r.store.Get(ctx, query)
|
|
}
|
|
|
|
func (r *RepositoryImpl) Delete(ctx context.Context, params *annotations.DeleteParams) error {
|
|
return r.store.Delete(ctx, params)
|
|
}
|
|
|
|
func (r *RepositoryImpl) FindTags(ctx context.Context, query *annotations.TagsQuery) (annotations.FindTagsResult, error) {
|
|
return r.store.GetTags(ctx, query)
|
|
}
|