Skip to content

Commit

Permalink
Full support for API v1 (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgmv authored Nov 5, 2024
1 parent d2a000d commit 7e6eddc
Show file tree
Hide file tree
Showing 28 changed files with 2,860 additions and 400 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Exampe for environment variables
SD_DB=postgresql://pg:pass@localhost:5432/status_dashboard
SD_CACHE=internal
#SD_LOG_LEVEL=devel
SD_LOG_LEVEL=devel
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ linters-settings:
allow-no-explanation: [ funlen, gocognit, lll ]
# Enable to require an explanation of nonzero length after each nolint directive.
# Default: false
require-explanation: true
require-explanation: false
# Enable to require nolint directives to mention the specific linter being suppressed.
# Default: false
require-specific: true
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ SHELL=/bin/bash
SD_DB?="postgresql://pg:pass@localhost:5432/status_dashboard?sslmode=disable"

test:
@echo running tests
go test ./... -count 1
@echo running unit tests
go test ./internal/... -count 1

test-acc:
@echo running integrational tests with docker and db
go test ./tests/... -count 1

build:
@echo build app
Expand Down
5 changes: 5 additions & 0 deletions docs/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Status dashboard documentation

## Table of contents

- [Incident creation for API V1](./v1/v1_incident_creation.md)
295 changes: 295 additions & 0 deletions docs/v1/incident_creation.drawio

Large diffs are not rendered by default.

Binary file added docs/v1/incident_creation.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions docs/v1/v1_incident_creation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Incident management V1 (short description)

## Prerequisites

In this document described the business logic schema for incident management. All actions require authorisation.

### User experience
Web page `/incidents`

On the page, user should fill `Incident Title`, `impact`, affected services and start date. All data in the form are required.
After that, in the system will be created a record about this incident.

### API experience
API endpoint is `/v1/component_status`

Metric processor can create an incident via API. But the logic a bit different from user experience.
```python
class ComponentStatusArgsSchema(Schema):
impact = fields.Integer(required=True)
name = fields.String(required=True)
text = fields.String(required=False, dump_default="Incident")
attributes = fields.List(fields.Nested(ComponentAttributeSchema))

```
Only `impact` and `name` are required.

Documentation from source code (can be outdated):

<details><summary>Documentation</summary>

Update component status

Process component status update and open new incident if required:

- current active maintenance for the component - do nothing
- current active incident for the component - do nothing
- current active incident NOT for the component - add component into
the list of affected components
- no active incidents - create new one
- current active incident for the component and requested
impact > current impact - run handling:

If a component exists in an incident, but the requested
impact is higher than the current one, then the component
will be moved to another incident if it exists with the
requested impact, otherwise a new incident will be created
and the component will be moved to the new incident.
If there is only one component in an incident, and an
incident with the requested impact does not exist,
then the impact of the incident will be changed to a higher
one, otherwise the component will be moved to an existing
incident with the requested impact, and the current incident
will be closed by the system.
The movement of a component and the closure of an incident
will be reflected in the incident statuses.

This method requires authorization to be used.
</details>

Based on the source code the schema for API will be:

![incident creation](incident_creation.drawio.png)
61 changes: 60 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ require (
github.com/gin-gonic/gin v1.10.0
github.com/joho/godotenv v1.5.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/lib/pq v1.10.9
github.com/ory/dockertest/v3 v3.11.0
github.com/stretchr/testify v1.9.0
go.uber.org/zap v1.27.0
gorm.io/driver/postgres v1.5.9
Expand All @@ -15,41 +17,98 @@ require (
)

require (
dario.cat/mergo v1.0.1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Masterminds/squirrel v1.5.4 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/bytedance/sonic v1.12.1 // indirect
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/containerd/continuity v0.4.3 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/cpuguy83/dockercfg v0.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/cli v27.3.1+incompatible // indirect
github.com/docker/docker v27.3.1+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.22.0 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.6.0 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.3.0 // indirect
github.com/moby/sys/userns v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/opencontainers/runc v1.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/testcontainers/testcontainers-go v0.34.0 // indirect
github.com/testcontainers/testcontainers-go/modules/postgres v0.34.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.9.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 7e6eddc

Please sign in to comment.