Skip to content

Commit

Permalink
CI fixes (#25)
Browse files Browse the repository at this point in the history
* fix upstream CI, correct linting errors in codebase
  • Loading branch information
pleimer authored Mar 10, 2021
1 parent 897df52 commit 98ae035
Show file tree
Hide file tree
Showing 48 changed files with 411 additions and 364 deletions.
29 changes: 21 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,44 @@ jobs:
golangci:
name: Linting
runs-on: ubuntu-20.04
container: 'quay.io/plmr/sg-core-ci'
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.16'
- name: tidy
run: go mod tidy
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
# Caching conflicts happen in GHA, so just disable for now
skip-pkg-cache: true
skip-build-cache: true
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.33

test-framework:
name: Base testing
name: Unit tests
runs-on: ubuntu-20.04

container: 'quay.io/plmr/sg-core-ci'
steps:
- name: Set up Go
uses: actions/setup-go@v1
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.14'
- name: Checkout code
uses: actions/checkout@v2
go-version: '1.16'
- name: tidy
run: go mod tidy
- name: Run unit tests and code coverage
run: go test -v -coverprofile=profile.cov ./...
- name: Send coverage
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: profile.cov
image-build:
name: Image build
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Verify image builds
run: |
docker build --tag infrawatch/sg-core:latest --file build/Dockerfile .
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/updates.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Coveralls Badge
on: pull_request
on:
pull_request:
types:
- opened

jobs:
coveralls_badge:
Expand All @@ -26,4 +29,4 @@ jobs:
body: `[![Coverage Status](https://coveralls.io/repos/github/${context.repo.owner}/${context.repo.repo}/badge.svg?branch=${BRANCH_NAME})](https://coveralls.io/github/${context.repo.owner}/${context.repo.repo}?branch=${BRANCH_NAME})`
})
env:
BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
58 changes: 58 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
run:
skip-dirs:
- plugins/transport/dummy-alertmanager
- plugins/transport/dummy-events
- plugins/transport/dummy-metrics
- plugins/transport/dummy-logs
- plugins/application/print
- devenv
issues:
exclude-rules:
- linters:
- errcheck
text: "[a-zA-Z]+.[a-zA-Z]+.(Error|Info|Debug|Warn)" # from logger
- text: "[A-Z]+" #omit enums
linters:
- deadcode
- text: New
linters:
- deadcode

linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
# - exhaustive
# - gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- golint
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- noctx
- nolintlint
- rowserrcheck
- scopelint
- staticcheck
- structcheck
- stylecheck
- typecheck
# - unused
- unconvert
- unparam
- varcheck
# - whitespace

2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN dnf install golang git -y --setopt=tsflags=nodocs
RUN CONTAINER_BUILD=true ./build.sh

# --- end build, create smart gateway layer ---
FROM registry.access.redhat.com/ubi8
FROM registry.access.redhat.com/ubi8-minimal

LABEL io.k8s.display-name="Smart Gateway" \
io.k8s.description="A component of the Service Telemetry Framework on the server side that ingests data from AMQP 1.x and provides a metrics scrape endpoint for Prometheus, and forwards events to ElasticSearch" \
Expand Down
12 changes: 8 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
func main() {
configPath := flag.String("config", "/etc/sg-core.conf.yaml", "configuration file path")
cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file")
//memprofile := flag.String("memprofile", "", "write cpu profile to file")
// memprofile := flag.String("memprofile", "", "write cpu profile to file")
flag.Usage = func() {
fmt.Printf("Usage: %s [OPTIONS]\n\nAvailable options:\n", os.Args[0])
flag.PrintDefaults()
Expand All @@ -40,7 +40,11 @@ func main() {
logger.Metadata(logging.Metadata{"error": err})
logger.Error("failed to start cpu profile")
}
pprof.StartCPUProfile(f)
err = pprof.StartCPUProfile(f)
if err != nil {
logger.Metadata(logging.Metadata{"error": err})
logger.Error("failed to start cpu profile")
}
defer pprof.StopCPUProfile()
}

Expand Down Expand Up @@ -107,9 +111,9 @@ func main() {

ctx, cancelCtx := context.WithCancel(context.Background())
wg := new(sync.WaitGroup)
//run main processes
// run main processes

pluginDone := make(chan bool) //notified if a plugin stops execution before main or interrupt Received
pluginDone := make(chan bool) // notified if a plugin stops execution before main or interrupt Received
interrupt := make(chan bool)
manager.RunTransports(ctx, wg, pluginDone, configuration.HandlerErrors)
manager.RunApplications(ctx, wg, pluginDone)
Expand Down
18 changes: 9 additions & 9 deletions cmd/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
"gopkg.in/yaml.v2"
)

//errors
// errors
var (
//ErrAppNotReceiver return if application plugin does not implement any receiver. In this case, it will receive no messages from the internal buses
// ErrAppNotReceiver return if application plugin does not implement any receiver. In this case, it will receive no messages from the internal buses
ErrAppNotReceiver = errors.New("application plugin does not implement either application.MetricReceiver or application.EventReceiver")
)
var (
Expand All @@ -39,17 +39,17 @@ func init() {
pluginPath = "/usr/lib64/sg-core"
}

//SetPluginDir set directory path containing plugin binaries
// SetPluginDir set directory path containing plugin binaries
func SetPluginDir(path string) {
pluginPath = path
}

//SetLogger set logger
// SetLogger set logger
func SetLogger(l *logging.Logger) {
logger = l
}

//InitTransport load tranpsort binary and initialize with config
// InitTransport load tranpsort binary and initialize with config
func InitTransport(name string, config interface{}) error {
n, err := initPlugin(name)
if err != nil {
Expand All @@ -75,7 +75,7 @@ func InitTransport(name string, config interface{}) error {
return nil
}

//InitApplication initialize application plugin with configuration
// InitApplication initialize application plugin with configuration
func InitApplication(name string, config interface{}) error {
n, err := initPlugin(name)
if err != nil {
Expand Down Expand Up @@ -121,7 +121,7 @@ func InitApplication(name string, config interface{}) error {
return nil
}

//SetTransportHandlers load handlers binaries for transport
// SetTransportHandlers load handlers binaries for transport
func SetTransportHandlers(name string, handlerBlocks []struct {
Name string `validate:"required"`
Config interface{}
Expand Down Expand Up @@ -156,7 +156,7 @@ func SetTransportHandlers(name string, handlerBlocks []struct {
return nil
}

//RunTransports spins off tranpsort + handler processes
// RunTransports spins off tranpsort + handler processes
func RunTransports(ctx context.Context, wg *sync.WaitGroup, done chan bool, report bool) {
for name, t := range transports {
for _, h := range handlers[name] {
Expand All @@ -183,7 +183,7 @@ func RunTransports(ctx context.Context, wg *sync.WaitGroup, done chan bool, repo
}
}

//RunApplications spins off application processes
// RunApplications spins off application processes
func RunApplications(ctx context.Context, wg *sync.WaitGroup, done chan bool) {
for _, a := range applications {
wg.Add(1)
Expand Down
6 changes: 3 additions & 3 deletions generator/amqp_snd_th.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static void send_message(app_data_t *app, pn_link_t *sender, pn_rwbytes_t *data)
}

static bool send_burst(app_data_t *app, pn_event_t *event) {
// pn_link_t *sender = pn_event_link(event);
// pn_link_t *sender = pn_event_link(event);
pn_link_t *sender = app->sender;

int credits = pn_link_credit(sender);
Expand Down Expand Up @@ -210,7 +210,7 @@ static bool handle(app_data_t *app, pn_event_t *event) {
if (app->verbose > 1) {
printf("PN_LINK_FLOW %d\n", pn_link_credit(sender));
}
//printf("link_credits: %d, sent: %ld\n",pn_link_credit(sender), app->amqp_sent );
// printf("link_credits: %d, sent: %ld\n",pn_link_credit(sender), app->amqp_sent );
exit_code = send_burst(app, event);
break;
}
Expand Down Expand Up @@ -265,7 +265,7 @@ static bool handle(app_data_t *app, pn_event_t *event) {
}
pn_connection_t *c = pn_event_connection(event);
pn_connection_set_container(c, app->container_id);
//pn_connection_open(c);
// pn_connection_open(c);

pn_session_t *s = pn_session(c);
pn_session_open(s);
Expand Down
19 changes: 10 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ go 1.14

require (
collectd.org v0.5.0
github.com/elastic/go-elasticsearch/v7 v7.5.1-0.20201228183019-1cbb255902f5
github.com/go-ini/ini v1.62.0 // indirect
github.com/go-openapi/errors v0.19.9
github.com/elastic/go-elasticsearch/v7 v7.11.0
github.com/go-openapi/errors v0.20.0
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/google/uuid v1.0.0
github.com/infrawatch/apputils v0.0.0-20210218211331-9f6eb5097d89
github.com/google/uuid v1.2.0
github.com/infrawatch/apputils v0.0.0-20210308125437-598b321f4335
github.com/json-iterator/go v1.1.10
github.com/leodido/go-urn v1.2.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.9.0
github.com/stretchr/testify v1.6.1
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
github.com/stretchr/testify v1.7.0
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/go-playground/assert.v1 v1.2.1
gopkg.in/go-playground/validator.v9 v9.31.0
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)
26 changes: 13 additions & 13 deletions pkg/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/infrawatch/sg-core/pkg/data"
)

//package application defines the interfaces for interacting with application plugins
// package application defines the interfaces for interacting with application plugins

// Application describes application plugin interfaces.
// Configuration bytes are passed into the Config() function as a sequence of bytes in yaml format. It is recommended to use the config.ParseConfig() method to parse the input. This is a convenience method that uses the validations library to validate the input and provide specific feedback.
Expand All @@ -17,25 +17,25 @@ type Application interface {
Run(context.Context, chan bool)
}

//MetricReceiver Receives metrics from the internal metrics bus
// MetricReceiver Receives metrics from the internal metrics bus
type MetricReceiver interface {
Application
// The ReceiveMetric function will be called every time a Metric is Received on the internal metrics bus. Each part of the metric is passed in as an argument to the function in the following order: name, epoch time, metric type, interval, value, label keys, label values.
//The last two arguments are gauranteed to be the same size and map index to index. Implementors of this function should run as quickly as possible as metrics can be very high volume. It is recommended to cache metrics in a data.Metric{} object to be utilized by the application plugin later.
// The ReceiveMetric function will be called every time a Metric is Received on the internal metrics bus. Each part of the metric is passed in as an argument to the function in the following order: name, epoch time, metric type, interval, value, label keys, label values.
// The last two arguments are guaranteed to be the same size and map index to index. Implementors of this function should run as quickly as possible as metrics can be very high volume. It is recommended to cache metrics in a data.Metric{} object to be utilized by the application plugin later.
ReceiveMetric(
string, //name
float64, //epoch time
data.MetricType, //type
time.Duration, //interval
float64, //value
[]string, //labelKeys
[]string, //labelValues
string, // name
float64, // epoch time
data.MetricType, // type
time.Duration, // interval
float64, // value
[]string, // labelKeys
[]string, // labelValues
)
}

//EventReceiver Receive events from the internal event bus
// EventReceiver Receive events from the internal event bus
type EventReceiver interface {
Application
//ReceiveEvent is called whenever an event is broadcast on the event bus.
// ReceiveEvent is called whenever an event is broadcast on the event bus.
ReceiveEvent(data.Event)
}
Loading

0 comments on commit 98ae035

Please sign in to comment.