Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
[issue-160] Fix Slack Incompatibility Error (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethen authored Oct 25, 2023
1 parent 75565f5 commit 3dcb2a1
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
# await script({github, context, core})

e2e-test:
runs-on: ubuntu-latest
runs-on: larger-runner
steps:
- uses: actions/checkout@v3

Expand Down
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
run:
# Analysis timeout, e.g. 30s, 5m.
# Default: 1m
timeout: 3m
timeout: 5m

# https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
linters-settings:
Expand Down Expand Up @@ -220,4 +220,4 @@ issues:
- noctx
- wrapcheck
- lll
- whitespace
- whitespace
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GREEN = \033[0;32m
BLUE = \033[0;34m
COLOR_END = \033[0;39m

TEST_LIMIT = 120s
TEST_LIMIT = 500s

build-app:
@echo "$(BLUE)» building application binary... $(COLOR_END)"
Expand Down Expand Up @@ -68,4 +68,4 @@ metrics-docs: build-app

devnet-allocs:
@echo "$(GREEN) Generating devnet allocs...$(COLOR_END)"
@./scripts/devnet-allocs.sh
@./scripts/devnet-allocs.sh
18 changes: 17 additions & 1 deletion docs/architecture/alerting.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,23 @@ An alert destination is a configurable destination that an alert can be sent to.

#### Slack

The Slack alert destination is a configurable destination that allows alerts to be sent to a specific Slack channel. The Slack alert destination will be configured with a Slack webhook URL. The Slack alert destination will then use this URL to send alerts to the specified Slack channel.
The Slack alert destination is a configurable destination that allows alerts to be sent to a specific Slack channel. The Slack alert destination will be configured with a Slack webhook URL. The Slack alert destination will then use this URL to send alerts to the specified Slack channel.

#### Setting up Slack
1. Add the [Incoming WebHooks](https://test-2kg5313.slack.com/apps/A0F7XDUAZ-incoming-webhooks?utm_source=in-prod&utm_medium=inprod-btn_app_install-index-click&tab=more_info) app to your Slack workspace.
2. Using the app, add a new webhook to your workspace for some specific channel.
3. Copy the webhook URL into an [alert routing](../alert-routing.md) entry for some severity level. This should look something like:
```yml
alertRoutes:
low:
slack:
low_oncall:
url: "https://hooks.slack.com/services/{API_KEY}"
channel: "#make-onchain-less-boring"

```

Done! You should now see any generated alerts being forwarded to your specified Slack channel.

#### PagerDuty

Expand Down
48 changes: 31 additions & 17 deletions e2e/alerting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (
"github.com/base-org/pessimism/internal/api/models"
"github.com/base-org/pessimism/internal/core"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// TestMultiDirectiveRouting ... Tests the E2E flow of a contract event heuristic with high priority alerts all
Expand All @@ -24,49 +26,61 @@ func TestMultiDirectiveRouting(t *testing.T) {
updateSig := "ConfigUpdate(uint256,uint8,bytes)"
alertMsg := "System config gas config updated"

_, err := ts.App.BootStrap([]*models.SessionRequestParams{{
ids, err := ts.App.BootStrap([]*models.SessionRequestParams{{
Network: core.Layer1.String(),
PType: core.Live.String(),
HeuristicType: core.ContractEvent.String(),
StartHeight: nil,
EndHeight: nil,
AlertingParams: &core.AlertPolicy{
Msg: alertMsg,
Sev: core.HIGH.String(),
Sev: core.HIGH.String(), // The use of HIGH priority should trigger all alert destinations
},
SessionParams: map[string]interface{}{
"address": ts.Cfg.L1Deployments.SystemConfigProxy.String(),
"args": []interface{}{updateSig},
},
}})

assert.NoError(t, err, "Error bootstrapping heuristic session")
require.Len(t, ids, 1, "Incorrect number of heuristic sessions created")
require.NoError(t, err, "Error bootstrapping heuristic session")

sysCfg, err := bindings.NewSystemConfig(ts.Cfg.L1Deployments.SystemConfigProxy, ts.L1Client)
assert.NoError(t, err, "Error getting system config")
require.NoError(t, err, "Error getting system config")

opts, err := bind.NewKeyedTransactorWithChainID(ts.Cfg.Secrets.SysCfgOwner, ts.Cfg.L1ChainIDBig())
assert.NoError(t, err, "Error getting system config owner pk")
require.NoError(t, err, "Error getting system config owner pk")

overhead := big.NewInt(10000)
scalar := big.NewInt(1)

tx, err := sysCfg.SetGasConfig(opts, overhead, scalar)
assert.NoError(t, err, "Error setting gas config")
require.NoError(t, err, "Error setting gas config")

receipt, err := wait.ForReceipt(context.Background(), ts.L1Client, tx.Hash(), types.ReceiptStatusSuccessful)

txTimeoutDuration := 10 * time.Duration(ts.Cfg.DeployConfig.L1BlockTime) * time.Second
receipt, err := e2e.WaitForTransaction(tx.Hash(), ts.L1Client, txTimeoutDuration)
require.NoError(t, err, "Error waiting for transaction")
require.Equal(t, receipt.Status, types.ReceiptStatusSuccessful, "transaction failed")

assert.NoError(t, err, "Error waiting for transaction")
assert.Equal(t, receipt.Status, types.ReceiptStatusSuccessful, "transaction failed")
// Wait for Pessimism to process the newly emitted event and send a notification to the mocked Slack
// and PagerDuty servers.
require.NoError(t, wait.For(context.Background(), 500*time.Millisecond, func() (bool, error) {
pUUID := ids[0].PUUID
height, err := ts.Subsystems.PipelineHeight(pUUID)
if err != nil {
return false, err
}

return height.Uint64() > receipt.BlockNumber.Uint64(), nil
}))

time.Sleep(3 * time.Second)
slackPosts := ts.TestSlackSvr.SlackAlerts()
pdPosts := ts.TestPagerDutyServer.PagerDutyAlerts()

// Expect 2 alerts to each destination as alert-routing-cfg.yaml has two slack and two pagerduty destinations
assert.Equal(t, 2, len(slackPosts), "Incorrect Number of slack posts sent")
assert.Equal(t, 2, len(pdPosts), "Incorrect Number of pagerduty posts sent")
require.Equal(t, 2, len(slackPosts), "Incorrect Number of slack posts sent")
require.Equal(t, 2, len(pdPosts), "Incorrect Number of pagerduty posts sent")

assert.Contains(t, slackPosts[0].Text, "contract_event", "System contract event alert was not sent")
assert.Contains(t, slackPosts[1].Text, "contract_event", "System contract event alert was not sent")
assert.Contains(t, pdPosts[0].Payload.Summary, "contract_event", "System contract event alert was not sent")
Expand Down Expand Up @@ -103,11 +117,11 @@ func TestCoolDown(t *testing.T) {
},
}})

assert.NoError(t, err, "Failed to bootstrap balance enforcement heuristic session")
require.NoError(t, err, "Failed to bootstrap balance enforcement heuristic session")

// Get Alice's balance.
aliceAmt, err := ts.L2Geth.L2Client.BalanceAt(context.Background(), alice, nil)
assert.NoError(t, err, "Failed to get Alice's balance")
require.NoError(t, err, "Failed to get Alice's balance")

// Determine the gas cost of the transaction.
gasAmt := 1_000_001
Expand All @@ -133,15 +147,15 @@ func TestCoolDown(t *testing.T) {

// Send the transaction to drain Alice's account of almost all ETH.
_, err = ts.L2Geth.AddL2Block(context.Background(), drainAliceTx)
assert.NoError(t, err, "Failed to create L2 block with transaction")
require.NoError(t, err, "Failed to create L2 block with transaction")

// Wait for Pessimism to process the balance change and send a notification to the mocked Slack server.
time.Sleep(2 * time.Second)

// Check that the balance enforcement was triggered using the mocked server cache.
posts := ts.TestSlackSvr.SlackAlerts()

assert.Equal(t, 1, len(posts), "No balance enforcement alert was sent")
require.Equal(t, 1, len(posts), "No balance enforcement alert was sent")
assert.Contains(t, posts[0].Text, "balance_enforcement", "Balance enforcement alert was not sent")
assert.Contains(t, posts[0].Text, alertMsg)

Expand Down
Loading

0 comments on commit 3dcb2a1

Please sign in to comment.