Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New store for alert event data. #2725

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,159 changes: 0 additions & 1,159 deletions Gopkg.lock

This file was deleted.

79 changes: 0 additions & 79 deletions Gopkg.toml

This file was deleted.

1 change: 1 addition & 0 deletions alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ func (n *AlertNode) newAlertState(tags models.Tags) *alertState {
}

func (n *AlertNode) restoreEvent(id string) (alert.Level, time.Time) {
//panic("NOT IMPLEMENTED")
var topicState, anonTopicState alert.EventState
var anonFound, topicFound bool
// Check for previous state on anonTopic
Expand Down
51 changes: 43 additions & 8 deletions alert/topics.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,26 @@ func (s *Topics) Close() error {
return nil
}

// Topic returns the topic with the given id, and if it exists or not
func (s *Topics) Topic(id string) (*Topic, bool) {
s.mu.RLock()
t, ok := s.topics[id]
s.mu.RUnlock()
return t, ok
}

func (s *Topics) RestoreTopic(id string, eventStates map[string]EventState) {
func (s *Topics) RestoreTopicNoCopy(topic string, eventStates map[string]*EventState) {
s.mu.Lock()
defer s.mu.Unlock()
t, ok := s.topics[topic]
if !ok {
t = s.newTopic(topic)
s.topics[topic] = t
}
t.restoreEventStatesNoCopy(eventStates)
}

func (s *Topics) RestoreTopic(id string, eventStates map[string]*EventState) {
s.mu.Lock()
defer s.mu.Unlock()
t, ok := s.topics[id]
Expand All @@ -66,13 +78,21 @@ func (s *Topics) RestoreTopic(id string, eventStates map[string]EventState) {
t.restoreEventStates(eventStates)
}

func (s *Topics) UpdateEvent(id string, event EventState) {
func (s *Topics) RestoreTopics() {
s.mu.Lock()
defer s.mu.Unlock()
t, ok := s.topics[id]
for _, t := range s.topics {
t.restoreEventStates(t.events)
}
}

func (s *Topics) UpdateEvent(topicID string, event EventState) {

s.mu.Lock()
defer s.mu.Unlock()
t, ok := s.topics[topicID]
if !ok {
t = s.newTopic(id)
s.topics[id] = t
s.topics[topicID] = s.newTopic(topicID)
}
t.updateEvent(event)
}
Expand Down Expand Up @@ -104,7 +124,6 @@ func (s *Topics) Collect(event Event) error {
}
s.mu.Unlock()
}

return topic.collect(event)
}

Expand Down Expand Up @@ -266,14 +285,26 @@ func (t *Topic) removeHandler(h Handler) {
}
}

func (t *Topic) restoreEventStates(eventStates map[string]EventState) {
func (t *Topic) restoreEventStatesNoCopy(eventStates map[string]*EventState) {
t.mu.Lock()
defer t.mu.Unlock()
t.events = make(map[string]*EventState, len(eventStates))
t.sorted = make([]*EventState, 0, len(eventStates))
for id, state := range eventStates {
t.events[id] = state
t.sorted = append(t.sorted, state)
}
sort.Sort(sortedStates(t.sorted))
}

func (t *Topic) restoreEventStates(eventStates map[string]*EventState) {
t.mu.Lock()
defer t.mu.Unlock()
t.events = make(map[string]*EventState, len(eventStates))
t.sorted = make([]*EventState, 0, len(eventStates))
for id, state := range eventStates {
e := new(EventState)
*e = state
*e = *state
t.events[id] = e
t.sorted = append(t.sorted, e)
}
Expand Down Expand Up @@ -315,16 +346,19 @@ func (t *Topic) close() {
}

func (t *Topic) collect(event Event) error {

prev, ok := t.updateEvent(event.State)
if ok {
event.previousState = prev
}

t.collected.Add(1)

return t.handleEvent(event)
}

func (t *Topic) handleEvent(event Event) error {

t.mu.RLock()
defer t.mu.RUnlock()

Expand Down Expand Up @@ -374,6 +408,7 @@ func (t *Topic) updateEvent(state EventState) (EventState, bool) {

type sortedStates []*EventState

// TODO(docmerlin): replaced sortedStates with a heap or something similar
func (e sortedStates) Len() int { return len(e) }
func (e sortedStates) Swap(i int, j int) { e[i], e[j] = e[j], e[i] }
func (e sortedStates) Less(i int, j int) bool {
Expand Down
15 changes: 15 additions & 0 deletions alert/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ type Event struct {
previousState EventState
}

func (e Event) MarshalBinary() (data []byte, err error) {
//TODO implement me
panic("implement me")
}

func (e Event) UnmarshalBinary(data []byte) error {
//TODO implement me
panic("implement me")
}

func (e Event) ObjectID() string {
//TODO implement me
panic("implement me")
}

func (e Event) AlertData() Data {
return Data{
ID: e.State.ID,
Expand Down
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ BUILD_NUM=${BUILD_NUM-$RANDOM}
HOME_DIR=/root

imagename=kapacitor-builder-img-$BUILD_NUM
PROTO_VERSION=3.18.3

# Build new docker image
docker build -f Dockerfile_build_ubuntu64 -t $imagename $DIR
docker build -f Dockerfile_build_ubuntu64 --build-arg PROTO_VERSION=$PROTO_VERSION -t $imagename $DIR

echo "Running build.py"
# Run docker
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ require (
github.com/urfave/cli/v2 v2.3.0
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c
github.com/zeebo/mwc v0.0.4
go.etcd.io/bbolt v1.3.5
go.etcd.io/bbolt v1.3.6
go.uber.org/zap v1.16.0
golang.org/x/crypto v0.0.0-20220214200702-86341886e292
golang.org/x/tools v0.1.11-0.20220513221640-090b14e8501f
Expand Down Expand Up @@ -262,3 +262,5 @@ replace k8s.io/client-go => k8s.io/client-go v0.20.5
replace k8s.io/api => k8s.io/api v0.20.5

replace github.com/dgrijalva/jwt-go => github.com/Waterdrips/jwt-go v3.2.1-0.20200915121943-f6506928b72e+incompatible

replace go.etcd.io/bbolt => github.com/0x0177b11f/bbolt v1.3.7-0.20220308103559-afc583528bb7
7 changes: 3 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ collectd.org v0.3.0/go.mod h1:A/8DzQBkF6abtvrT2j/AU/4tiBgJWYyh0y/oB/4MlWE=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20201218220906-28db891af037/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zumjgTw83q2ge/PI+yyw8=
github.com/0x0177b11f/bbolt v1.3.7-0.20220308103559-afc583528bb7 h1:VbZYwrPh0R9OxStYGcn7WeB6vfcXCMpwEvPAAXGYJtw=
github.com/0x0177b11f/bbolt v1.3.7-0.20220308103559-afc583528bb7/go.mod h1:sh/Yp01MYDakY7RVfzKZn+T1WOMTTFJrWjl7+M73RXA=
github.com/AlecAivazis/survey/v2 v2.2.9 h1:LWvJtUswz/W9/zVVXELrmlvdwWcKE60ZAw0FWV9vssk=
github.com/AlecAivazis/survey/v2 v2.2.9/go.mod h1:9DYvHgXtiXm6nCn+jXnOXLKbH+Yo9u8fAS/SduGdoPk=
github.com/Azure/azure-pipeline-go v0.2.3 h1:7U9HBg1JFK3jHl5qmo4CTZKFTVgMwdFHMVtCdfBE21U=
Expand Down Expand Up @@ -1338,10 +1340,6 @@ github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
github.com/zeebo/mwc v0.0.4 h1:9dNXNLtUB4lUXoXgyhy3YrKoV0OD7oRiu907YMS0nl0=
github.com/zeebo/mwc v0.0.4/go.mod h1:qNHfgp/ZCpQNcJHwKcO5EP3VgaBrW6DPohsK4QfyxxE=
github.com/zeebo/xxh3 v0.13.0/go.mod h1:AQY73TOrhF3jNsdiM9zZOb8MThrYbZONHj7ryDBaLpg=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
go.mongodb.org/mongo-driver v1.0.3/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
go.mongodb.org/mongo-driver v1.1.1/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
Expand Down Expand Up @@ -1641,6 +1639,7 @@ golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200828194041-157a740278f4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201112073958-5cba982894dd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
Loading