...

Source file src/github.com/chaos-mesh/chaos-mesh/pkg/dashboard/core/event.go

Documentation: github.com/chaos-mesh/chaos-mesh/pkg/dashboard/core

     1  // Copyright 2021 Chaos Mesh Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  // http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //
    15  
    16  package core
    17  
    18  import (
    19  	"context"
    20  	"time"
    21  )
    22  
    23  // EventStore defines operations for working with events.
    24  type EventStore interface {
    25  	// List returns an event list from the datastore.
    26  	List(context.Context) ([]*Event, error)
    27  
    28  	// ListByUID returns an event list by the UID.
    29  	ListByUID(context.Context, string) ([]*Event, error)
    30  
    31  	// ListByUIDs returns an event list by the UID list.
    32  	ListByUIDs(context.Context, []string) ([]*Event, error)
    33  
    34  	// ListByExperiment returns an event list by the namespace, name, or kind.
    35  	ListByExperiment(context context.Context, namespace string, name string, kind string) ([]*Event, error)
    36  
    37  	ListByFilter(context.Context, Filter) ([]*Event, error)
    38  
    39  	// Find returns an event by ID.
    40  	Find(context.Context, uint) (*Event, error)
    41  
    42  	// Create persists a new event to the datastore.
    43  	Create(context.Context, *Event) error
    44  
    45  	// DeleteByUID deletes events by the UID.
    46  	DeleteByUID(context.Context, string) error
    47  
    48  	// DeleteByUIDs deletes events by the UID list.
    49  	DeleteByUIDs(context.Context, []string) error
    50  
    51  	// DeleteByTime deletes events within the specified time interval.
    52  	DeleteByTime(context.Context, string, string) error
    53  
    54  	// DeleteByDuration selete events that exceed duration.
    55  	DeleteByDuration(context.Context, time.Duration) error
    56  }
    57  
    58  type Event struct {
    59  	ID        uint      `gorm:"primary_key" json:"id"`
    60  	ObjectID  string    `gorm:"index:object_id" json:"object_id"`
    61  	CreatedAt time.Time `json:"created_at"`
    62  	Namespace string    `json:"namespace"`
    63  	Name      string    `json:"name"`
    64  	Kind      string    `json:"kind"`
    65  	Type      string    `json:"type"`
    66  	Reason    string    `json:"reason"`
    67  	Message   string    `gorm:"type:text;size:32768" json:"message"`
    68  }
    69