Skip to content

Commit

Permalink
fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
almostinf committed Aug 7, 2024
2 parents ec217d7 + ebd4d4d commit 6600553
Show file tree
Hide file tree
Showing 424 changed files with 14,379 additions and 5,992 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@ jobs:
- name: Run linter
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.54.2
only-new-issues: true
version: v1.56.2

4 changes: 2 additions & 2 deletions .github/workflows/publish-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up Ruby 2.6
- name: Set up Ruby 3.3
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
ruby-version: 3.3

- name: Install fpm
run: gem install fpm
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/swagger-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: '16.16.0'
node-version: '20.11.0'
- run: npm install --location=global @openapitools/openapi-generator-cli
- run: make spec
- run: make validate-spec
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
cache-dependency-path: go.sum

- name: Run tests
run: make test
run: make ci-test

- name: Upload coverage to Codecov
run: bash <(curl -s https://codecov.io/bash)
15 changes: 15 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,30 @@ linters:
- asciicheck
- bidichk
- bodyclose
- decorder
- dogsled
- errcheck
- errorlint
- exportloopref
- goconst
- gocheckcompilerdirectives
- gocyclo
- goconst
- godot
- gofmt
- gofumpt
- goheader
- goimports
- gomnd
- gosimple
- govet
- grouper
- ineffassign
- loggercheck
- makezero
- misspell
- nilerr
- noctx
- prealloc
- promlinter
- staticcheck
Expand All @@ -55,8 +66,12 @@ issues:
- path: _test\.go
linters:
- gomnd
- errcheck
- goconst

run:
timeout: 5m
skip-files:
- notifier/registrator.go
skip-dirs:
- vendor
2 changes: 1 addition & 1 deletion Dockerfile.api
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19 as builder
FROM golang:1.21 as builder

COPY go.mod go.sum /go/src/github.com/moira-alert/moira/
WORKDIR /go/src/github.com/moira-alert/moira
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.checker
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19 as builder
FROM golang:1.21 as builder

COPY go.mod go.sum /go/src/github.com/moira-alert/moira/
WORKDIR /go/src/github.com/moira-alert/moira
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.cli
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19 as builder
FROM golang:1.21 as builder

COPY go.mod go.sum /go/src/github.com/moira-alert/moira/
WORKDIR /go/src/github.com/moira-alert/moira
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.filter
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19 as builder
FROM golang:1.21 as builder

COPY go.mod go.sum /go/src/github.com/moira-alert/moira/
WORKDIR /go/src/github.com/moira-alert/moira
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.notifier
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19 as builder
FROM golang:1.21 as builder

COPY go.mod go.sum /go/src/github.com/moira-alert/moira/
WORKDIR /go/src/github.com/moira-alert/moira
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ validate-spec:
test:
echo 'mode: atomic' > coverage.txt && go list ./... | xargs -n1 -I{} sh -c 'go test -race -v -bench=. -covermode=atomic -coverprofile=coverage.tmp {} && tail -n +2 coverage.tmp >> coverage.txt' && rm coverage.tmp

.PHONY: ci-test
ci-test:
echo 'mode: atomic' > coverage.txt && go list ./... | xargs -n1 -I{} sh -c 'go test -race -v -covermode=atomic -coverprofile=coverage.tmp {} && tail -n +2 coverage.tmp >> coverage.txt' && rm coverage.tmp

.PHONY: build
build:
for service in "filter" $(SERVICES) ; do \
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Moira 2.0 ![Build Status](https://github.com/moira-alert/moira/actions/workflows/test.yml/badge.svg?branch=master) [![codecov](https://codecov.io/gh/moira-alert/moira/branch/master/graph/badge.svg)](https://codecov.io/gh/moira-alert/moira) [![Documentation Status](https://readthedocs.org/projects/moira/badge/?version=latest)](http://moira.readthedocs.io/en/latest/?badge=latest) [![Telegram](https://img.shields.io/badge/telegram-join%20chat-3796cd.svg)](https://t.me/moira_alert) [![Go Report Card](https://goreportcard.com/badge/github.com/moira-alert/moira)](https://goreportcard.com/report/github.com/moira-alert/moira)

Moira is a real-time alerting tool, based on [Graphite](https://graphite.readthedocs.io) data.
Moira is a real-time alerting tool, based on [Graphite](https://graphite.readthedocs.io) or [Prometheus](https://prometheus.io/)/[VictoriaMetrics](https://victoriametrics.com/) metrics.

## Installation

Expand Down Expand Up @@ -41,6 +41,7 @@ Code in this repository is the backend part of Moira monitoring application.
* [doc](https://github.com/moira-alert/doc) is the documentation (hosted on [Read the Docs](https://moira.readthedocs.io)).
* [moira-trigger-role](https://github.com/moira-alert/moira-trigger-role) is the Ansible role you can use to manage triggers.
* [python-moira-client](https://github.com/moira-alert/python-moira-client) is the Python API client.
* [go-client](https://github.com/moira-alert/client-go) is the GO API client.

## Contact us

Expand Down
42 changes: 42 additions & 0 deletions api/authorization.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package api

// Authorization contains authorization configuration.
type Authorization struct {
AdminList map[string]struct{}
Enabled bool
AllowedContactTypes map[string]struct{}
}

// IsEnabled returns true if auth is enabled and false otherwise.
func (auth *Authorization) IsEnabled() bool {
return auth.Enabled
}

// IsAdmin checks whether given user is considered an administrator.
func (auth *Authorization) IsAdmin(login string) bool {
if !auth.IsEnabled() {
return false
}
_, ok := auth.AdminList[login]
return ok
}

// The Role is an enumeration that represents the scope of user's permissions.
type Role string

var (
RoleUndefined Role = ""
RoleUser Role = "user"
RoleAdmin Role = "admin"
)

// Returns the role of the given user.
func (auth *Authorization) GetRole(login string) Role {
if !auth.IsEnabled() {
return RoleUndefined
}
if auth.IsAdmin(login) {
return RoleAdmin
}
return RoleUser
}
70 changes: 48 additions & 22 deletions api/config.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,62 @@
package api

import "time"
import (
"net/http"
"time"

"github.com/moira-alert/moira"
)

// WebContact is container for web ui contact validation.
type WebContact struct {
ContactType string `json:"type" example:"webhook"`
ContactLabel string `json:"label" example:"Webhook"`
LogoURI string `json:"logo_uri,omitempty" example:"discord-logo.svg"`
ValidationRegex string `json:"validation,omitempty" example:"^(http|https):\\/\\/.*(moira.ru)(:[0-9]{2,5})?\\/"`
Placeholder string `json:"placeholder,omitempty" example:"https://moira.ru/webhooks"`
Help string `json:"help,omitempty" example:"### Domains whitelist:\n - moira.ru\n"`
}

// FeatureFlags is struct to manage feature flags.
type FeatureFlags struct {
IsPlottingDefaultOn bool `json:"isPlottingDefaultOn" example:"false"`
IsPlottingAvailable bool `json:"isPlottingAvailable" example:"true"`
IsSubscriptionToAllTagsAvailable bool `json:"isSubscriptionToAllTagsAvailable" example:"false"`
IsReadonlyEnabled bool `json:"isReadonlyEnabled" example:"false"`
}

// Sentry - config for sentry settings.
type Sentry struct {
DSN string `json:"dsn,omitempty" example:"https://[email protected]"`
Platform string `json:"platform,omitempty" example:"dev"`
}

// Config for api configuration variables.
type Config struct {
EnableCORS bool
Listen string
GraphiteLocalMetricTTL time.Duration
GraphiteRemoteMetricTTL time.Duration
PrometheusRemoteMetricTTL time.Duration
EnableCORS bool
Listen string
MetricsTTL map[moira.ClusterKey]time.Duration
Flags FeatureFlags
Authorization Authorization
}

// WebConfig is container for web ui configuration parameters.
type WebConfig struct {
SupportEmail string `json:"supportEmail,omitempty"`
RemoteAllowed bool `json:"remoteAllowed"`
Contacts []WebContact `json:"contacts"`
FeatureFlags FeatureFlags `json:"featureFlags"`
SupportEmail string `json:"supportEmail,omitempty" example:"[email protected]"`
RemoteAllowed bool `json:"remoteAllowed" example:"true"`
MetricSourceClusters []MetricSourceCluster `json:"metric_source_clusters"`
Contacts []WebContact `json:"contacts"`
FeatureFlags FeatureFlags `json:"featureFlags"`
Sentry Sentry `json:"sentry"`
}

// WebContact is container for web ui contact validation.
type WebContact struct {
ContactType string `json:"type"`
ContactLabel string `json:"label"`
ValidationRegex string `json:"validation,omitempty"`
Placeholder string `json:"placeholder,omitempty"`
Help string `json:"help,omitempty"`
// MetricSourceCluster contains data about supported metric source cluster.
type MetricSourceCluster struct {
TriggerSource moira.TriggerSource `json:"trigger_source" example:"graphite_remote"`
ClusterId moira.ClusterId `json:"cluster_id" example:"default"`
ClusterName string `json:"cluster_name" example:"Graphite Remote Prod"`
}

// FeatureFlags is struct to manage feature flags.
type FeatureFlags struct {
IsPlottingDefaultOn bool `json:"isPlottingDefaultOn"`
IsPlottingAvailable bool `json:"isPlottingAvailable"`
IsSubscriptionToAllTagsAvailable bool `json:"isSubscriptionToAllTagsAvailable"`
func (WebConfig) Render(w http.ResponseWriter, r *http.Request) error {
return nil
}
Loading

0 comments on commit 6600553

Please sign in to comment.