Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run test and lint during CI #23

Merged
merged 5 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: ci
on: ["push", "pull_request"]

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
cache: true
- run: make lint
- run: make fmt
- name: Verify repo is up-to-date
run: |
if [ -n "$(git status --porcelain)" ]; then
echo 'Updates required:'
git status
exit 1
fi

run-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
cache: true
- name: Run tests
run: make test
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
STATES_DIR=$(CURDIR)/.states
DIST_DIR=$(CURDIR)/dist

MODULE_DEPS=$(sort $(shell go list -deps -tags=darwin,linux,windows -f "{{with .Module}}{{if not .Main}}{{.Path}}{{end}}{{end}}" ./...))

all: test

fmt: tools/go.mod
Expand All @@ -12,7 +14,10 @@ fmt: tools/go.mod
lint: tools/go.mod
go run -modfile=tools/go.mod honnef.co/go/tools/cmd/staticcheck -checks=all ./...
go list -m -json $(MODULE_DEPS) | go run -modfile=tools/go.mod go.elastic.co/go-licence-detector \
-includeIndirect -rules tools/notice/rules.json -validate
-includeIndirect \
-rules tools/notice/rules.json \
-noticeTemplate tools/notice/NOTICE.txt.tmpl \
-noticeOut NOTICE.txt
go mod tidy && git diff --exit-code

.PHONY: clean
Expand Down Expand Up @@ -64,8 +69,6 @@ publish: IMAGE_REF=$$(cat "$(STATES_DIR)/image_ref")
publish:
docker push $(IMAGE_REF)

MODULE_DEPS=$(sort $(shell go list -deps -tags=darwin,linux,windows -f "{{with .Module}}{{if not .Main}}{{.Path}}{{end}}{{end}}" ./...))

notice: NOTICE.txt
NOTICE.txt: go.mod tools/go.mod
go list -m -json $(MODULE_DEPS) | go run -modfile=tools/go.mod go.elastic.co/go-licence-detector \
Expand Down
16,042 changes: 15,923 additions & 119 deletions NOTICE.txt

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions cmd/apmbench/bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import (
"testing"
"time"

"github.com/elastic/apm-perf/internal/loadgen"
loadgencfg "github.com/elastic/apm-perf/internal/loadgen/config"
"github.com/elastic/apm-perf/internal/loadgen/eventhandler"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"golang.org/x/time/rate"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"

"github.com/elastic/apm-perf/internal/loadgen"
loadgencfg "github.com/elastic/apm-perf/internal/loadgen/config"
"github.com/elastic/apm-perf/internal/loadgen/eventhandler"

"go.elastic.co/apm/v2"
"go.elastic.co/apm/v2/transport"
)
Expand Down Expand Up @@ -109,9 +110,9 @@ func Benchmark10000AggregationGroups(b *testing.B, l *rate.Limiter) {
}
tx := tracer.StartTransaction(fmt.Sprintf("name%d", i), fmt.Sprintf("type%d", i))
span := tx.StartSpanOptions(fmt.Sprintf("name%d", i), fmt.Sprintf("type%d", i), apm.SpanOptions{})
span.Context.SetDestinationService(apm.DestinationServiceSpanContext{
Name: fmt.Sprintf("name%d", i),
Resource: fmt.Sprintf("resource%d", i),
span.Context.SetServiceTarget(apm.ServiceTargetSpanContext{
Name: fmt.Sprintf("name%d", i),
Type: fmt.Sprintf("resource%d", i),
})
span.Duration = time.Second
span.End()
Expand Down
5 changes: 3 additions & 2 deletions cmd/apmbench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (
"testing"
"time"

"github.com/elastic/apm-perf/internal/otelcollector"
"go.uber.org/zap"

"github.com/elastic/apm-perf/internal/otelcollector"
)

func main() {
Expand All @@ -26,7 +27,7 @@ func main() {
}

extraMetrics := func(*testing.B) error { return nil }
resetFunc := func() { return }
resetFunc := func() {}
if cfg.CollectorConfigYaml != "" {
logger.Info("starting otel collector...")

Expand Down
5 changes: 3 additions & 2 deletions cmd/apmbench/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import (
"strings"
"testing"

"github.com/elastic/apm-perf/internal/loadgen"
loadgencfg "github.com/elastic/apm-perf/internal/loadgen/config"
"go.elastic.co/apm/v2/stacktrace"
"golang.org/x/time/rate"

"github.com/elastic/apm-perf/internal/loadgen"
loadgencfg "github.com/elastic/apm-perf/internal/loadgen/config"
)

const benchmarkFuncPrefix = "Benchmark"
Expand Down
8 changes: 4 additions & 4 deletions cmd/apmsoak/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ type RunOptions struct {
ScenariosPath string
ServerURL string
SecretToken string
ApiKeys string
APIKeys string
BypassProxy bool
}

func (opts *RunOptions) toRunnerConfig() (*soaktest.RunnerConfig, error) {
apiKeys := make(map[string]string)
pairs := strings.Split(opts.ApiKeys, ",")
pairs := strings.Split(opts.APIKeys, ",")
for _, pair := range pairs {
kv := strings.Split(pair, ":")
if len(kv) != 2 {
Expand All @@ -41,7 +41,7 @@ func (opts *RunOptions) toRunnerConfig() (*soaktest.RunnerConfig, error) {
ScenariosPath: opts.ScenariosPath,
ServerURL: opts.ServerURL,
SecretToken: opts.SecretToken,
ApiKeys: apiKeys,
APIKeys: apiKeys,
BypassProxy: opts.BypassProxy,
}, nil
}
Expand Down Expand Up @@ -78,7 +78,7 @@ func NewCmdRun() *cobra.Command {
cmd.Flags().StringVar(&options.Scenario, "scenario", "steady", "Specify which scenario to use. the value should match one of the scenario key defined in given scenarios YAML file")
cmd.Flags().StringVarP(&options.ScenariosPath, "file", "f", "./scenarios.yml", "Path to scenarios file")
cmd.Flags().StringVar(&options.SecretToken, "secret-token", "", "Secret token for APM Server. Managed intake service doesn't support secret token")
cmd.Flags().StringVar(&options.ApiKeys, "api-keys", "", "API keys for managed service. Specify key value pairs as `project_id_1:my_api_key,project_id_2:my_key`")
cmd.Flags().StringVar(&options.APIKeys, "api-keys", "", "API keys for managed service. Specify key value pairs as `project_id_1:my_api_key,project_id_2:my_key`")
cmd.Flags().BoolVar(&options.BypassProxy, "bypass-proxy", false, "Detach from proxy dependency and provide projectID via header. Useful when testing locally")
return cmd
}
1 change: 1 addition & 0 deletions internal/loadgen/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// or more contributor license agreements. Licensed under the Elastic License 2.0;
// you may not use this file except in compliance with the Elastic License 2.0.

// Package loadgencfg contains configuration related code for load generator.
package loadgencfg

import (
Expand Down
1 change: 1 addition & 0 deletions internal/loadgen/eventhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// or more contributor license agreements. Licensed under the Elastic License 2.0;
// you may not use this file except in compliance with the Elastic License 2.0.

// Package loadgen contains code for generating load based on real agent data.
package loadgen

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/loadgen/eventhandler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// or more contributor license agreements. Licensed under the Elastic License 2.0;
// you may not use this file except in compliance with the Elastic License 2.0.

// Package eventhandler contains code for replaying batch of agent data to APM
// server.
package eventhandler

import (
Expand Down
8 changes: 6 additions & 2 deletions internal/otelcollector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// or more contributor license agreements. Licensed under the Elastic License 2.0;
// you may not use this file except in compliance with the Elastic License 2.0.

// Package otelcollector contains code for OTEL based in-memory telemetry
// collector responsible for exposing OTEL receiver endpoints, caching telemetry
// data sentand providing queryable interface for the collected data.
package otelcollector

import (
Expand All @@ -10,7 +13,6 @@ import (
"fmt"
"time"

"github.com/elastic/apm-perf/internal/otelcollector/exporter/inmemexporter"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/exporter"
Expand All @@ -22,6 +24,8 @@ import (
"go.opentelemetry.io/collector/service/telemetry"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

"github.com/elastic/apm-perf/internal/otelcollector/exporter/inmemexporter"
)

// Collector defines an OTEL collector for collecting metrics. Services
Expand Down Expand Up @@ -108,7 +112,7 @@ func (c *Collector) Shutdown() error {
return nil
}

// GetAggregatedMetrics returns a aggregated value for the given
// GetAggregatedMetric returns a aggregated value for the given
// aggregation config.
func (c *Collector) GetAggregatedMetric(
cfg inmemexporter.AggregationConfig,
Expand Down
3 changes: 2 additions & 1 deletion internal/otelcollector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"fmt"
"os"

"github.com/elastic/apm-perf/internal/otelcollector/exporter/inmemexporter"
"go.uber.org/zap/zapcore"
"gopkg.in/yaml.v3"

"github.com/elastic/apm-perf/internal/otelcollector/exporter/inmemexporter"
)

// CollectorConfig defines the configuration to customize the collector.
Expand Down
3 changes: 2 additions & 1 deletion internal/otelcollector/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
"path"
"testing"

"github.com/elastic/apm-perf/internal/otelcollector/exporter/inmemexporter"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/elastic/apm-perf/internal/otelcollector/exporter/inmemexporter"
)

func TestLoadConfigFromYamlFile(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// or more contributor license agreements. Licensed under the Elastic License 2.0;
// you may not use this file except in compliance with the Elastic License 2.0.

// Package inmemexporter contains code for creating an in-memory OTEL exporter.
package inmemexporter

import (
Expand Down
6 changes: 4 additions & 2 deletions internal/soaktest/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// or more contributor license agreements. Licensed under the Elastic License 2.0;
// you may not use this file except in compliance with the Elastic License 2.0.

// Package soaktest contains code for defining soak testing scenarios and providing
// an interface for running them.
package soaktest

import (
Expand Down Expand Up @@ -29,7 +31,7 @@ type RunnerConfig struct {
ScenariosPath string
ServerURL string
SecretToken string
ApiKeys map[string]string
APIKeys map[string]string
BypassProxy bool
}

Expand Down Expand Up @@ -124,7 +126,7 @@ func getHandlerParams(runnerConfig *RunnerConfig, config ScenarioConfig) (loadge
return params, err
}
if config.APIKey == "" {
config.APIKey = runnerConfig.ApiKeys[config.ProjectID]
config.APIKey = runnerConfig.APIKeys[config.ProjectID]
}

burst, interval, err := getEventRate(config.EventRate)
Expand Down
1 change: 1 addition & 0 deletions internal/version/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// or more contributor license agreements. Licensed under the Elastic License 2.0;
// you may not use this file except in compliance with the Elastic License 2.0.

// Package version contains metadata for commands.
package version

import (
Expand Down
Loading