Skip to content

Commit

Permalink
Merge pull request #1 from redBorder/feature/incident_response
Browse files Browse the repository at this point in the history
 Feature/incident response
  • Loading branch information
manegron authored Jul 16, 2024
2 parents 4ded547 + 12ba92d commit c02f58e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
43 changes: 38 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func main() {

// Read the configuration
config, err := readConfig(*configFile)
if err != nil {
if (err != nil) {
log.Fatalf("Error reading config: %v", err)
}

Expand All @@ -72,7 +72,7 @@ func main() {
var allKeys []string
for _, server := range config.MemcachedServers {
keys, err := getAllKeysFromMemcached(server)
if err != nil {
if (err != nil) {
log.Printf("Error getting keys from server %s: %v", server, err)
} else {
allKeys = append(allKeys, keys...)
Expand All @@ -88,8 +88,24 @@ func main() {
item, err := mc.Get(key)

if err != nil {
log.Printf("Error getting key %s: %v", key, err)
continue
if err == memcache.ErrCacheMiss {
// If cache miss, check all servers for the key
for _, server := range config.MemcachedServers {
mcSingle := memcache.New(server)
item, err = mcSingle.Get(key)
if err == nil {
log.Printf("Key %s found on server %s", key, server)
break
} else if err != memcache.ErrCacheMiss {
log.Printf("Error getting key %s from server %s: %v", key, server, err)
}
}
}

if err != nil {
log.Printf("Key %s not found on any server: %v", key, err)
continue
}
}

// Deserialize escaped JSON
Expand Down Expand Up @@ -119,8 +135,25 @@ func main() {
if created {
// Delete the key from Memcached if the incident was created successfully
err = mc.Delete(key)

if err != nil {
log.Printf("Error deleting key %s: %v", key, err)
if err == memcache.ErrCacheMiss {
// If cache miss, check all servers for the key
for _, server := range config.MemcachedServers {
mcSingle := memcache.New(server)
err = mcSingle.Delete(key)
if err == nil {
log.Printf("Successfully deleted key %s after creating incident", key)
break
} else if err != memcache.ErrCacheMiss {
log.Printf("Error getting key %s from server %s: %v", key, server, err)
}
}
}
if err != nil {
log.Printf("Error deleting key %s: %v", key, err)
continue
}
} else {
log.Printf("Successfully deleted key %s after creating incident", key)
}
Expand Down

0 comments on commit c02f58e

Please sign in to comment.