Skip to content

Commit

Permalink
flowcontrol: restructure codebase II (#898)
Browse files Browse the repository at this point in the history
### Description of change
Making room for adding more APIs (adapters, previews etc) under
flowcontrol.

##### Checklist

- [X] Tested in playground or other setup
  • Loading branch information
harjotgill authored and hdkshingala committed Nov 7, 2022
1 parent dd430b4 commit 11e8e12
Show file tree
Hide file tree
Showing 71 changed files with 2,018 additions and 1,980 deletions.
10 changes: 4 additions & 6 deletions api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ buf-generate:
@find . -name \*.pb.go -exec protoc-go-inject-tag -input={} \;
@#generate sdk flowcontrol stubs and copy them over
@#golang
@rm -rf ../sdks/aperture-go/gen/proto/flowcontrol
@cp -R gen/proto/go/aperture/flowcontrol ../sdks/aperture-go/gen/proto/flowcontrol
@rm -rf ../sdks/aperture-go/gen/proto/flowcontrol/check
@cp -R gen/proto/go/aperture/flowcontrol/check ../sdks/aperture-go/gen/proto/flowcontrol/check
@#java
@rm -rf ../sdks/aperture-java/src/main/java/com/fluxninja/generated
@cp -R gen/proto/java/com/fluxninja/generated ../sdks/aperture-java/src/main/java/com/fluxninja/generated
@rm -rf ../sdks/aperture-java/src/main/java/com/fluxninja/generated/aperture/*
@cp -R gen/proto/java/com/fluxninja/generated/aperture/flowcontrol ../sdks/aperture-java/src/main/java/com/fluxninja/generated/aperture/flowcontrol
@rm -rf ../sdks/aperture-java/src/main/java/com/fluxninja/generated/aperture/flowcontrol/*
@cp -R gen/proto/java/com/fluxninja/generated/aperture/flowcontrol/check ../sdks/aperture-java/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check
@rm -rf gen/proto/java
@#generate api docs
@rm -rfd $(DOCS_OPENAPI)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syntax = "proto3";

package aperture.flowcontrol.v1;
package aperture.flowcontrol.check.v1;

import "google/protobuf/timestamp.proto";

Expand Down

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/sdk-validator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
"github.com/fluxninja/aperture/cmd/sdk-validator/validator"
"github.com/fluxninja/aperture/pkg/log"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/sdk-validator/validator/flowcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"google.golang.org/grpc/peer"
"google.golang.org/protobuf/types/known/timestamppb"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
"github.com/fluxninja/aperture/pkg/log"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/sdk-validator/validator/provide.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"go.uber.org/fx"
"google.golang.org/grpc"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
"github.com/fluxninja/aperture/pkg/log"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/sdk-validator/validator/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"go.uber.org/multierr"
"google.golang.org/protobuf/encoding/protojson"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
"github.com/fluxninja/aperture/pkg/log"
"github.com/fluxninja/aperture/pkg/otelcollector"
)
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ require (
github.com/prometheus/prometheus v0.39.1 // indirect
github.com/tchap/go-patricia/v2 v2.3.1 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.11.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.11.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.11.1 // indirect
golang.org/x/tools v0.2.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
gonum.org/v1/gonum v0.12.0 // indirect
Expand Down Expand Up @@ -256,6 +258,7 @@ require (
go.opentelemetry.io/collector/semconv v0.63.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.4 // indirect
go.opentelemetry.io/contrib/zpages v0.36.4 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.11.1
go.opentelemetry.io/otel/exporters/prometheus v0.33.0 // indirect
go.opentelemetry.io/otel/metric v0.33.0 // indirect
go.opentelemetry.io/otel/sdk v1.11.1 // indirect
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,13 @@ go.opentelemetry.io/contrib/zpages v0.36.4 h1:Z2VK5WsDhWs9VwZ1p0TM5RyusTOgAQfdMM
go.opentelemetry.io/contrib/zpages v0.36.4/go.mod h1:h1gnOu0cOfDGEncNgLsjQ5H/9eAzt9LXsa1WvH7I5KU=
go.opentelemetry.io/otel v1.11.1 h1:4WLLAmcfkmDk2ukNXJyq3/kiz/3UzCaYq6PskJsaou4=
go.opentelemetry.io/otel v1.11.1/go.mod h1:1nNhXBbWSD0nsL38H6btgnFN2k4i0sNLHNNMZMSbUGE=
go.opentelemetry.io/otel/exporters/otlp v0.20.0 h1:PTNgq9MRmQqqJY0REVbZFvwkYOA85vbdQU/nVfxDyqg=
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.11.1 h1:X2GndnMCsUPh6CiY2a+frAbNsXaPLbB0soHRYhAZ5Ig=
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.11.1/go.mod h1:i8vjiSzbiUC7wOQplijSXMYUpNM93DtlS5CbUT+C6oQ=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.11.1 h1:MEQNafcNCB0uQIti/oHgU7CZpUMYQ7qigBwMVKycHvc=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.11.1/go.mod h1:19O5I2U5iys38SsmT2uDJja/300woyzE1KPIQxEUBUc=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.11.1 h1:LYyG/f1W/jzAix16jbksJfMQFpOH/Ma6T639pVPMgfI=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.11.1/go.mod h1:QrRRQiY3kzAoYPNLP0W/Ikg0gR6V3LMc+ODSxr7yyvg=
go.opentelemetry.io/otel/exporters/prometheus v0.33.0 h1:xXhPj7SLKWU5/Zd4Hxmd+X1C4jdmvc0Xy+kvjFx2z60=
go.opentelemetry.io/otel/exporters/prometheus v0.33.0/go.mod h1:ZSmYfKdYWEdSDBB4njLBIwTf4AU2JNsH3n2quVQDebI=
go.opentelemetry.io/otel/metric v0.33.0 h1:xQAyl7uGEYvrLAiV/09iTJlp1pZnQ9Wl793qbVvED1E=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
"github.com/rs/zerolog"
"go.opentelemetry.io/collector/pdata/pcommon"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
"google.golang.org/protobuf/types/known/timestamppb"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
"github.com/fluxninja/aperture/pkg/otelcollector"
"github.com/fluxninja/aperture/pkg/otelcollector/metricsprocessor/internal"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/otelcollector/metricsprocessor/internal/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"go.opentelemetry.io/collector/pdata/pcommon"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
"github.com/fluxninja/aperture/pkg/metrics"
"github.com/fluxninja/aperture/pkg/otelcollector"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/otelcollector/metricsprocessor/internal/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
. "github.com/onsi/gomega"
"go.opentelemetry.io/collector/pdata/pcommon"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
"github.com/fluxninja/aperture/pkg/metrics"
"github.com/fluxninja/aperture/pkg/otelcollector"
"github.com/fluxninja/aperture/pkg/otelcollector/metricsprocessor/internal"
Expand Down
2 changes: 1 addition & 1 deletion pkg/otelcollector/metricsprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
"github.com/fluxninja/aperture/pkg/log"
"github.com/fluxninja/aperture/pkg/metrics"
"github.com/fluxninja/aperture/pkg/otelcollector"
Expand Down
2 changes: 1 addition & 1 deletion pkg/otelcollector/metricsprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"
"k8s.io/apimachinery/pkg/util/json"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
m "github.com/fluxninja/aperture/pkg/metrics"
oc "github.com/fluxninja/aperture/pkg/otelcollector"
"github.com/fluxninja/aperture/pkg/policies/mocks"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"go.uber.org/fx"
"go.uber.org/multierr"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
policylangv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/policy/language/v1"
policysyncv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/policy/sync/v1"
"github.com/fluxninja/aperture/pkg/agentinfo"
Expand Down
2 changes: 1 addition & 1 deletion pkg/policies/flowcontrol/actuators/rate/rate-limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"go.uber.org/fx"
"go.uber.org/multierr"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
policylangv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/policy/language/v1"
policysyncv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/policy/sync/v1"
"github.com/fluxninja/aperture/pkg/agentinfo"
Expand Down
6 changes: 4 additions & 2 deletions pkg/policies/flowcontrol/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"golang.org/x/exp/maps"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
policylangv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/policy/language/v1"
"github.com/fluxninja/aperture/pkg/multimatcher"
"github.com/fluxninja/aperture/pkg/panichandler"
Expand Down Expand Up @@ -126,7 +126,9 @@ func (e *Engine) ProcessRequest(
return
}

func runLimiters(ctx context.Context, limiters []iface.Limiter, labels map[string]string) ([]*flowcontrolv1.LimiterDecision, flowcontrolv1.CheckResponse_DecisionType) {
func runLimiters(ctx context.Context, limiters []iface.Limiter, labels map[string]string) ([]*flowcontrolv1.LimiterDecision,
flowcontrolv1.CheckResponse_DecisionType,
) {
var wg sync.WaitGroup
var once sync.Once
decisions := make([]*flowcontrolv1.LimiterDecision, len(limiters))
Expand Down
2 changes: 1 addition & 1 deletion pkg/policies/flowcontrol/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
. "github.com/onsi/gomega"
goprom "github.com/prometheus/client_golang/prometheus"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
policylangv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/policy/language/v1"
"github.com/fluxninja/aperture/pkg/metrics"
"github.com/fluxninja/aperture/pkg/policies/flowcontrol/iface"
Expand Down
2 changes: 1 addition & 1 deletion pkg/policies/flowcontrol/iface/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package iface
import (
"context"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
"github.com/fluxninja/aperture/pkg/policies/flowcontrol/selectors"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/policies/flowcontrol/iface/limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"strconv"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
policylangv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/policy/language/v1"
"github.com/prometheus/client_golang/prometheus"
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/policies/flowcontrol/provide.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"go.uber.org/fx"

"github.com/fluxninja/aperture/pkg/policies/flowcontrol/actuators"
"github.com/fluxninja/aperture/pkg/policies/flowcontrol/api"
"github.com/fluxninja/aperture/pkg/policies/flowcontrol/resources/classifier"
"github.com/fluxninja/aperture/pkg/policies/flowcontrol/resources/fluxmeter"
"github.com/fluxninja/aperture/pkg/policies/flowcontrol/service"
)

// Module returns the fx options for dataplane side pieces of policy.
Expand All @@ -15,7 +15,7 @@ func Module() fx.Option {
actuators.Module(),
fluxmeter.Module(),
classifier.Module(),
api.Module(),
service.Module(),
fx.Provide(
NewEngine,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
policysyncv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/policy/sync/v1"
"github.com/fluxninja/aperture/pkg/log"
"github.com/fluxninja/aperture/pkg/metrics"
Expand All @@ -37,12 +37,12 @@ type rules struct {
type ClassificationEngine struct {
mu sync.Mutex
activeRules atomic.Value
classifierMapMutex sync.RWMutex
registry status.Registry
activeRulesets map[rulesetID]compiler.CompiledRuleset
nextRulesetID rulesetID
classifierMapMutex sync.RWMutex
classifierMap map[iface.ClassifierID]iface.Classifier
counterVec *prometheus.CounterVec
nextRulesetID rulesetID
}

type rulesetID = uint64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
. "github.com/onsi/gomega"
"github.com/open-policy-agent/opa/ast"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
policylangv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/policy/language/v1"
policysyncv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/policy/sync/v1"
"github.com/fluxninja/aperture/pkg/log"
Expand Down
2 changes: 1 addition & 1 deletion pkg/policies/flowcontrol/selectors/control-point.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package selectors
import (
"fmt"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
policylangv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/policy/language/v1"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package base
package check

import (
"context"
Expand All @@ -8,7 +8,7 @@ import (
"google.golang.org/grpc/peer"
"google.golang.org/protobuf/types/known/timestamppb"

flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
"github.com/fluxninja/aperture/pkg/entitycache"
"github.com/fluxninja/aperture/pkg/log"
"github.com/fluxninja/aperture/pkg/policies/flowcontrol/iface"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package base_test
package check_test

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package base_test
package check_test

import (
"context"
Expand All @@ -10,14 +10,14 @@ import (
"google.golang.org/grpc/peer"

entitycachev1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/entitycache/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/v1"
flowcontrolv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/flowcontrol/check/v1"
"github.com/fluxninja/aperture/pkg/agentinfo"
"github.com/fluxninja/aperture/pkg/config"
"github.com/fluxninja/aperture/pkg/entitycache"
grpcclient "github.com/fluxninja/aperture/pkg/net/grpc"
"github.com/fluxninja/aperture/pkg/platform"
"github.com/fluxninja/aperture/pkg/policies/flowcontrol"
"github.com/fluxninja/aperture/pkg/policies/flowcontrol/api/base"
"github.com/fluxninja/aperture/pkg/policies/flowcontrol/service/check"
)

var (
Expand Down Expand Up @@ -48,8 +48,8 @@ var _ = BeforeEach(func() {
}.Module(),
fx.Provide(agentinfo.ProvideAgentInfo),
fx.Supply(entities),
fx.Provide(base.ProvideNopMetrics),
fx.Provide(base.ProvideHandler),
fx.Provide(check.ProvideNopMetrics),
fx.Provide(check.ProvideHandler),
fx.Provide(flowcontrol.NewEngine),
grpcclient.ClientConstructor{Name: "flowcontrol-grpc-client", ConfigKey: "flowcontrol.client.grpc"}.Annotate(),
fx.Populate(&svc),
Expand Down
Loading

0 comments on commit 11e8e12

Please sign in to comment.