Skip to content

Commit

Permalink
feat: renamed apiserver to httpserver; (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
j4k4 authored and Jan Kamieth committed Feb 14, 2024
1 parent d1f763f commit d713c86
Show file tree
Hide file tree
Showing 19 changed files with 363 additions and 317 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ jobs:
go-version: '1.20'

- name: Check out code into the Go module directory
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Get dependencies
run: go get -v -t -d ./...

- name: Build
run: go build -v ./...
run: go build -a -v ./...

go-vet:
name: static code analysis (go vet)
Expand Down
106 changes: 25 additions & 81 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,34 @@ output:
print-issued-lines: true
print-linter-name: true

linters-settings:
dupl:
# tokens count to trigger issue
threshold: 100
linters:
enable:
- dupword # Checks for duplicate words in the source code.
- gci # Gci controls Go package import order and makes it always deterministic.
- gocognit # Computes and checks the cognitive complexity of functions.
- gocritic # Provides diagnostics that check for bugs, performance and style issues.
- godox # Tool for detection of FIXME, TODO and other comment keywords.
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string.
- misspell # Finds commonly misspelled English words in comments.
- nestif # Reports deeply nested if statements.
- nlreturn # Nlreturn checks for a new line before return and branch statements to increase code clarity.
- staticcheck # It's a set of rules from staticcheck.
- typecheck
enable-all: false
disable:
disable-all: true
presets:
fast: false

funlen:
lines: 60
statements: 40
goconst:
# minimal length of string constant, 3 by default
min-len: 3
# minimal occurrences count to trigger, 3 by default
min-occurrences: 2
linters-settings:
gocognit:
min-complexity: 20

gocritic:
enabled-checks:
disabled-checks:
- paramTypeCombine
- importShadow
enabled-tags:
- diagnostic
- style
Expand All @@ -38,84 +49,17 @@ linters-settings:
disabled-tags:
settings:

nestif:
# minimal complexity of if statements to report, 5 by default
min-complexity: 4

godox:
# Report any comments starting with keywords, this is useful for TODO or FIXME comments that
# might be left in the code accidentally and should be resolved before merging.
keywords:
- TODO
- BUG
- FIXME

lll:
# max line length, lines longer will be reported. Default is 120.
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
line-length: 150
# tab width in spaces. Default to 1.
tab-width: 1

unparam:
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: true

linters:
enable:
- govet
- godox # prevent leaving todos, fixmes, etc in the code
- funlen # functions longer than n lines will be reported
# - dupl
- misspell
- nestif
# - cyclop # cyclomatic complexity
- staticcheck
# - lll # max line length, lines longer will be reported
- dupword # prevent from having "there are no no values"
# - nilnil # prevent return nil, nil
# - nosprintfhostport # prevent host port via fmt.Println
# - ireturn # but maybe difficult to integrate because we return interface in multiple places
# - forcetypeassert # checking type of type assertion, not sure because of a lot of error messages
# - errname # checks that errors comes with golang convenient way
# - unused # unused variables
# - unparam
# - unconvert # unnecessary conversion
- gocritic # Almost 100 diagnostics that check for bugs, performance and style issues
# - goconst # checks occurrence of something and proposes to make it constant
# - nakedret # find naked returns in functions
# - depth # Count the maxdepth of go functions. It's helpful to see if a function needs to be splitted into several smaller functions
# - gochecknoinits # Check that no inits functions are present in Go code
# - errcheck # errcheck is a program for checking for unchecked errors in Go code. These unchecked errors can be critical bugs in some cases
# - ineffassign # Detects when assignments to existing variables are not used
# - dogsled # Checks if all structure fields are initialized
# - exhaustruct # Checks if all structure fields are initialized
# - exportloopref # checks for pointers to enclosing loop variables
# - gocognit # Computes and checks the cognitive complexity of functions
# - gosec # Inspects source code for security problems
# - importas # Enforces consistent import aliases
# - nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
# - noctx # finds sending http request without context.Context

enable-all: false
disable:
disable-all: true
presets:
fast: false

nestif:
min-complexity: 4

issues:
exclude-rules:
- path: _test\.go
linters:
- ireturn
- errcheck
- gosec
- funlen
- dupl
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0
Expand Down
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
terraform 1.5.6
golangci-lint 1.54.2
pre-commit 3.6.0
golang 1.20.14
16 changes: 8 additions & 8 deletions builder/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ type Dashboard struct {
}

type DashboardBuilder struct {
resourceNames ResourceNames
resourceNames *ResourceNames
panelFactories []PanelFactory
orchestrator string
}

func NewDashboardBuilder(resourceNames ResourceNames, orchestrator string) *DashboardBuilder {
func NewDashboardBuilder(resourceNames *ResourceNames, orchestrator string) *DashboardBuilder {
return &DashboardBuilder{
resourceNames: resourceNames,
panelFactories: make([]PanelFactory, 0),
Expand Down Expand Up @@ -61,13 +61,13 @@ func (d *DashboardBuilder) AddTraefikService() {
d.AddPanel(NewPanelTraefikRequestCountPerTarget)
}

func (d *DashboardBuilder) AddApiServerHandler(method string, path string) {
rowTitle := fmt.Sprintf("ApiServer: %s %s", method, path)
func (d *DashboardBuilder) AddHttpServerHandler(serverName string, handler MetadataHttpServerHandler) {
rowTitle := fmt.Sprintf("HttpServer %s: %s %s", serverName, handler.Method, handler.Path)

d.AddPanel(NewPanelRow(rowTitle))
d.AddPanel(NewPanelApiServerRequestCount(path))
d.AddPanel(NewPanelApiServerResponseTime(path))
d.AddPanel(NewPanelApiServerHttpStatus(path))
d.AddPanel(NewPanelHttpServerRequestCount(serverName, handler))
d.AddPanel(NewPanelHttpServerResponseTime(serverName, handler))
d.AddPanel(NewPanelHttpServerHttpStatus(serverName, handler))
}

func (d *DashboardBuilder) AddDynamoDbTable(table MetadataCloudAwsDynamodbTable) {
Expand Down Expand Up @@ -175,7 +175,7 @@ func (d *DashboardBuilder) Build() Dashboard {

func (d *DashboardBuilder) buildPanel(factory PanelFactory, x int, y int) Panel {
panelGridPos := NewPanelGridPos(PanelHeight, PanelWidth, x, y)
settings := newPaneSettings(d.resourceNames, panelGridPos, d.orchestrator)
settings := newPanelSettings(d.resourceNames, panelGridPos, d.orchestrator)
panel := factory(settings)

if panel.FieldConfig.Defaults.Custom.AxisPlacement == "" {
Expand Down
4 changes: 2 additions & 2 deletions builder/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestEcsDashboardWithError(t *testing.T) {
},
}

resourceNames := builder.ResourceNames{
resourceNames := &builder.ResourceNames{
CloudwatchNamespace: cloudwatchNamespace,
EcsCluster: ecsClusterName,
EcsService: ecsServiceName,
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestKubernetesDashboardWithError(t *testing.T) {
kubernetesPod := "pod"
var targetGroups []builder.ElbTargetGroup

resourceNames := builder.ResourceNames{
resourceNames := &builder.ResourceNames{
CloudwatchNamespace: cloudwatchNamespace,
EcsCluster: ecsClusterName,
EcsService: ecsServiceName,
Expand Down
68 changes: 0 additions & 68 deletions builder/metadata_apiserver.go

This file was deleted.

20 changes: 11 additions & 9 deletions builder/metadata_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,32 @@ import (
)

type MetadataApplication struct {
ApiServer MetadataApiServer `json:"apiserver"`
Cloud MetadataCloud `json:"cloud"`
Stream MetadataStream `json:"stream"`
Cloud MetadataCloud `json:"cloud"`
HttpServers MetadataHttpServers `json:"httpservers"`
Stream MetadataStream `json:"stream"`
}

func (a MetadataApplication) ToValue() types.Object {
return types.Object{
AttrTypes: MetadataApplicationAttrTypes(),
Attrs: map[string]attr.Value{
"apiserver": a.ApiServer.ToValue(),
"cloud": a.Cloud.ToValue(),
"stream": a.Stream.ToValue(),
"cloud": a.Cloud.ToValue(),
"httpservers": a.HttpServers.ToValue(),
"stream": a.Stream.ToValue(),
},
}
}

func MetadataApplicationAttrTypes() map[string]attr.Type {
return map[string]attr.Type{
"apiserver": types.ObjectType{
AttrTypes: MetadataApiserverAttrTypes(),
},
"cloud": types.ObjectType{
AttrTypes: MetadataCloudAttrTypes(),
},
"httpservers": types.ListType{
ElemType: types.ObjectType{
AttrTypes: MetadataHttpServerAttrTypes(),
},
},
"stream": types.ObjectType{
AttrTypes: MetadataStreamAttrTypes(),
},
Expand Down
11 changes: 11 additions & 0 deletions builder/metadata_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func MetadataCloudAttrTypes() map[string]attr.Type {
type MetadataCloudAws struct {
Dynamodb MetadataCloudAwsDynamodb `json:"dynamodb"`
Kinesis MetadataCloudAwsKinesis `json:"kinesis"`
Sns MetadataCloudAwsSns `json:"sns"`
Sqs MetadataCloudAwsSqs `json:"sqs"`
}

Expand Down Expand Up @@ -222,6 +223,16 @@ func MetadataCloudAwsKinesisRecordWriterAttrTypes() map[string]attr.Type {
}
}

type MetadataCloudAwsSnsTopic struct {
AwsClientName string `json:"aws_client_name"`
TopicArn string `json:"topic_arn"`
TopicName string `json:"topic_name"`
}

type MetadataCloudAwsSns struct {
Queues []MetadataCloudAwsSnsTopic `json:"topics"`
}

type MetadataCloudAwsSqsQueue struct {
AwsClientName string `json:"aws_client_name"`
QueueArn string `json:"queue_arn"`
Expand Down
Loading

0 comments on commit d713c86

Please sign in to comment.