Documentation
¶
Overview ¶
Package devmode is the development mode of `muster dev`: its published defaults, the rule that lets the environment replace them, the fake Alertmanager, Mattermost (two servers), Telegram, Slack and OIDC servers, the fake webhook receiver, the fake bridge and the fake HTTP and SOCKS5 proxies on fixed loopback addresses, the demo OIDC configuration, and Muster itself in the same process, against the development database and migrated on start, with the demo Integration that the fake Alertmanager sends to and the demo Connections to the fakes, whose Slack requests go to the fake Slack server (SlackRoute); the routes that send Connections on realistic addresses with the fakes' published tokens to the fakes (TelegramRoute, MattermostRoute, BridgeRoute); and the development clock that every replica of the development database shares.
Index ¶
- Constants
- func BridgeDemo() connections.Demo
- func BridgeRoute(baseURL string, token logging.Secret) string
- func ConnectionDemo() connections.Demo
- func IntegrationDemo() integrations.Demo
- func MattermostRoute(serverURL string, token logging.Secret) string
- func OIDCDemo() oidc.Demo
- func RegisterReceiver(f *fakealertmanager.Fake, ingestURL string) error
- func Run(ctx context.Context, w io.Writer, addrs Addresses, ...) error
- func RunReplica(ctx context.Context, w io.Writer, serve func(context.Context) error) error
- func SlackDemo() connections.Demo
- func SlackRoute(botToken logging.Secret) string
- func StartHeartbeat(ctx context.Context, f *fakealertmanager.Fake, ingestURL string) error
- func TelegramDemo() connections.Demo
- func TelegramRoute(baseURL string, token logging.Secret) string
- type Addresses
- type Applied
- type Clock
- type ClockQueries
- type ClockStore
- type Env
- type Fakes
- type OSEnv
Constants ¶
const ( // DevelopmentKey is the development master key; the server command refuses it outside development mode. DevelopmentKey = keyring.DevelopmentKey PublicURL = "http://localhost:8080" DatabaseURL = "postgres://muster:muster@127.0.0.1:55432/muster?sslmode=disable" AdminEmail = "admin@example.org" AdminPassword = "muster-dev-password" // OIDCClientID and OIDCClientSecret are the client of the demo OIDC configuration; the fake IdP accepts any secret. OIDCClientID = "muster-dev" OIDCClientSecret = "muster-dev-oidc-secret" OIDCDisplayName = "Example SSO" // OIDCDisplayNameWas is the display name that earlier versions gave the demo OIDC configuration, which a // development database may still hold; the start renames it. OIDCDisplayNameWas = "Dev IdP" // IngestURL is MUSTER_INGEST_URL in development mode: the ingest listener of `muster dev`. IngestURL = "http://localhost:8081" // IntegrationName is the demo Integration, IntegrationToken its published token and IntegrationReceiver the // fake Alertmanager's receiver that sends with it. IntegrationName = "dev-alertmanager" IntegrationToken = "mstr_int_devdevdevdevdevdevdevdevdevdevdevdevdevdevdevdevdevd" IntegrationReceiver = "muster" )
The development defaults, published so that anyone can run Muster locally.
const ( AlertmanagerAddr = "127.0.0.1:19093" MattermostAddr = "127.0.0.1:18065" // MattermostSecondAddr is the second fake Mattermost server, for several Mattermost Connections. MattermostSecondAddr = "127.0.0.1:18066" TelegramAddr = "127.0.0.1:18081" OIDCAddr = "127.0.0.1:18090" HTTPProxyAddr = "127.0.0.1:18091" SOCKSProxyAddr = "127.0.0.1:18092" WebhookAddr = "127.0.0.1:18093" BridgeAddr = "127.0.0.1:18094" SlackAddr = "127.0.0.1:18097" // LoopbackNetwork is added to the allowed networks of the development database, so that Muster may call the // fakes; a real installation keeps the standard policy. LoopbackNetwork = "127.0.0.0/8" // The listen addresses of `muster dev --replica`. ReplicaListenApp = ":9080" ReplicaListenIngest = ":9081" ReplicaListenInternal = ":9082" ReplicaLine = "muster dev: additional replica, no fake servers" )
const ( ConnectionName = "Example Mattermost" ConnectionBotToken = "muster-dev-mattermost-token" )
The demo Connection that `muster dev` ensures at start: "Example Mattermost" on the fake Mattermost server, with a published bot token that the fake accepts like any other.
const ( TelegramConnectionName = "Example Telegram" TelegramConnectionBotToken = "123456:dev-telegram-token" )
The demo Telegram Connection that `muster dev` ensures at start: "Example Telegram" on the fake Bot API, in the long-polling mode, with a published bot token that the fake accepts like any other.
const ( MattermostSecondBotToken = fakemattermost.SecondBotToken TelegramSecondBotToken = faketelegram.SecondBotToken BridgeSecondBotToken = fakebridge.SecondToken SlackSecondBotToken = fakeslack.SecondBotToken SlackSecondAppToken = fakeslack.SecondAppToken )
The published tokens of the second bots, which `muster dev` serves but configures no Connection for: the second bot of the fake Mattermost servers, of the fake Telegram server and of the fake bridge, and the bot token and app-level token of the fake Slack server's second app. Tests and checks create their Connections through the API.
const ( BridgeConnectionName = "Example Bridge" BridgeConnectionBotToken = fakebridge.Token )
The demo Bridge Connection that `muster dev` ensures at start: "Example Bridge" on the fake bridge, in poll mode, with the published token of the fake's first bot.
const ( SlackConnectionName = "Example Slack" SlackConnectionBotToken = fakeslack.BotToken SlackConnectionAppToken = fakeslack.AppToken )
The demo Slack Connection that `muster dev` ensures at start: "Example Slack" on the fake Slack server's first app, in socket mode, with its published bot token and app-level token.
const ( MattermostRouteURL = "https://chat.example.org" BridgeRouteURL = "https://bridge.example.org" )
The addresses whose Connections `muster dev` sends to the fake servers when their token is one of the fakes' published tokens (C-21.FR-10): the guides show these, never a fake server's loopback address. The Telegram one is the default Bot API base URL, telegram.DefaultBaseURL.
const AllowedInternalConnections = "localhost 127.0.0.1"
AllowedInternalConnections is what `muster dev` sets as the fake Mattermost's AllowedUntrustedInternalConnections, so that it calls the button presses back at MUSTER_INGEST_URL on loopback (F-022).
const ClockChannel = "dev_clock"
ClockChannel is the LISTEN/NOTIFY channel on which a change of the development clock reaches every replica.
const ClockPath = "/_dev/clock"
ClockPath is where the internal listener serves the development clock in development mode.
const HeartbeatInterval = 60
HeartbeatInterval is how often the fake Alertmanager signals the Heartbeat of the demo Integration.
const SlackBaseURL = "http://" + SlackAddr + "/api/"
SlackBaseURL is where `muster dev` sends the Web API requests of a Slack Connection of the fake Slack server's published tokens.
const TelegramCopyDelay = time.Second
TelegramCopyDelay is how long after a channel post its automatic copy reaches the bot in `muster dev`, about a quarter of the 4 s measured on the real service (F-005), so that the copy usually arrives after the answer to sendMessage, as there.
Variables ¶
This section is empty.
Functions ¶
func BridgeDemo ¶
func BridgeDemo() connections.Demo
BridgeDemo is the demo Connection "Example Bridge", to the fake bridge in poll mode, without Destinations.
func BridgeRoute ¶
BridgeRoute is the Bridge route of `muster dev`: a Bridge Connection on BridgeRouteURL whose token is one of the fake bridge's published tokens calls the fake bridge; any other address or token calls the address the Connection names.
func ConnectionDemo ¶
func ConnectionDemo() connections.Demo
ConnectionDemo is the demo Connection "Example Mattermost", to the fake Mattermost server, without Destinations.
func IntegrationDemo ¶
func IntegrationDemo() integrations.Demo
IntegrationDemo is the demo Integration that `muster dev` ensures at start: dev-alertmanager with the Static label cluster=dev, its Heartbeat on, and the published token that the fake Alertmanager's receiver muster and its Heartbeat sender send with.
func MattermostRoute ¶
MattermostRoute is the Mattermost route of `muster dev`: a Mattermost Connection on MattermostRouteURL whose bot token is one of the fake Mattermost server's published tokens calls the first fake Mattermost server; any other address or token calls the address the Connection names.
func OIDCDemo ¶
OIDCDemo is the demo OIDC configuration that `muster dev` stores at its first start on a database: OIDC against the fake IdP, with muster-admins mapped to Admin and oncall to Responder.
func RegisterReceiver ¶
func RegisterReceiver(f *fakealertmanager.Fake, ingestURL string) error
RegisterReceiver registers the receiver muster with the fake Alertmanager: the ingestion endpoint under ingestURL with the demo Integration's token.
func Run ¶
func Run(ctx context.Context, w io.Writer, addrs Addresses, serve func(context.Context) error) error
Run starts the fake servers at addrs, registers the receiver muster with the fake Alertmanager for MUSTER_INGEST_URL and starts its Heartbeat sender for the demo Integration, prints their addresses, then runs Muster in the same process with serve until ctx ends or serve fails; the fake servers stop after it.
func RunReplica ¶
RunReplica is `muster dev --replica`: it starts no fake server and runs Muster with serve, an additional replica against the same database.
func SlackDemo ¶
func SlackDemo() connections.Demo
SlackDemo is the demo Connection "Example Slack", on the fake Slack server's first app in socket mode, without Destinations; SlackRoute sends its requests to the fake server.
func SlackRoute ¶
SlackRoute is the Slack route of `muster dev` (C-01.FR-13): a Slack Connection whose bot token is one of the fake Slack server's published bot tokens calls the fake server at SlackBaseURL, with its bot token and its app-level token alike; any other calls Slack.
func StartHeartbeat ¶
StartHeartbeat starts the fake Alertmanager's Heartbeat sender muster: a signal of the demo Integration to the Heartbeat endpoint under ingestURL every HeartbeatInterval seconds, until the fake servers stop.
func TelegramDemo ¶
func TelegramDemo() connections.Demo
TelegramDemo is the demo Connection "Example Telegram", to the fake Telegram server in the long-polling mode, without Destinations.
func TelegramRoute ¶
TelegramRoute is the Telegram route of `muster dev`: a Telegram Connection on the default Bot API base URL whose bot token is one of the fake Telegram server's published tokens calls the fake server; any other address or token calls the address the Connection names.
Types ¶
type Addresses ¶
type Addresses struct {
Alertmanager, Mattermost, MattermostSecond, Telegram, OIDC, Webhook, Bridge, Slack string
HTTPProxy, SOCKSProxy string
}
Addresses are the listen addresses of the fake servers and the fake proxies.
func FakeAddresses ¶
func FakeAddresses() Addresses
FakeAddresses are the fixed addresses that later checks and the second replica rely on.
type Applied ¶
Applied names the variables, never their values: Defaults took their development default, FromEnv were set in the environment and kept a default out.
func Apply ¶
Apply sets the development defaults in env. A variable counts as set when it is present, even if empty; a set variable replaces its default and never adds to it, so a MUSTER_SECRET_KEYS from the environment is the whole Keyring. With replica, the listen addresses of an additional replica are defaults too.
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock is the development clock (C-01.FR-13): the offset of the business clock, stored in runtime_state.dev_clock_offset_seconds so that every replica of one database runs on the same clock. The real clock is never offset.
func NewClock ¶
func NewClock(s ClockStore, business *clock.Business, maintain func(ctx context.Context, at time.Time) error, changed ...func()) *Clock
NewClock returns the development clock that moves business; maintain runs partition maintenance as at a time, and each of changed that is not nil is called after each change of the offset, on every replica.
func (*Clock) Advance ¶
Advance moves the clock of every replica forward by seconds: it runs partition maintenance as at the new time, adds the seconds to the stored offset and notifies the replicas in one transaction, and returns once this replica runs on the new offset.
func (*Clock) Handler ¶
Handler serves GET and POST on ClockPath: GET reads the clock, POST {"advance_seconds": N} advances it by N seconds, N between 0 and ten years; both answer {"now", "offset_seconds"}.
func (*Clock) Load ¶
Load sets the business clock to the stored offset: at start, on each notification on ClockChannel and when the LISTEN is back after a loss.
func (*Clock) OffsetSeconds ¶
OffsetSeconds is how far the business clock of this replica runs ahead of the system time.
type ClockQueries ¶
type ClockQueries interface {
GetDevClockOffset(ctx context.Context) (int64, error)
AdvanceDevClock(ctx context.Context, arg dbgen.AdvanceDevClockParams) (int64, error)
NotifyDevClock(ctx context.Context, arg dbgen.NotifyDevClockParams) error
}
ClockQueries are the queries of the development clock; *dbgen.Queries implements them.
type ClockStore ¶
type ClockStore interface {
ClockQueries
InTx(ctx context.Context, f func(ClockQueries) error) error
}
ClockStore runs the queries alone or in one transaction.
func NewClockStore ¶
func NewClockStore(pool *pgxpool.Pool) ClockStore
NewClockStore is the ClockStore over the main pool.
type Fakes ¶
type Fakes struct {
Alertmanager *fakealertmanager.Fake
Mattermost *fakemattermost.Fake
// MattermostSecond is the second fake Mattermost server, with the same fixtures.
MattermostSecond *fakemattermost.Fake
Telegram *faketelegram.Fake
OIDC *fakeoidc.Fake
Webhook *fakewebhook.Fake
Bridge *fakebridge.Fake
Slack *fakeslack.Fake
HTTPProxy *fakeproxy.Server
SOCKSProxy *fakeproxy.Server
}
Fakes are the running fake servers and fake proxies.
func StartFakes ¶
StartFakes starts the fake servers and the fake proxies, both fake Mattermost servers allowing presses to call back on loopback; when one cannot listen, it closes those already started.