-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
220 additions
and
126 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package metricexporter | ||
|
||
import "context" | ||
|
||
type EdgeMetric interface { | ||
Record(ctx context.Context, from string, to string) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package metricexporter | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/otterize/network-mapper/src/mapper/pkg/intentsstore" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type MetricExporter struct { | ||
config Config | ||
edgeMetric EdgeMetric | ||
} | ||
|
||
func NewMetricExporter(ctx context.Context, config Config) (*MetricExporter, error) { | ||
em, err := NewOtelEdgeMetric(ctx, config.ExportInterval) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &MetricExporter{ | ||
config: config, | ||
edgeMetric: em, | ||
}, nil | ||
} | ||
|
||
func (o *MetricExporter) GetIntentCallback(ctx context.Context, intents []intentsstore.TimestampedIntent) { | ||
for _, intent := range intents { | ||
clientName := intent.Intent.Client.Name | ||
serverName := intent.Intent.Server.Name | ||
logrus.Debugf("recording metric counter: %s -> %s", clientName, serverName) | ||
o.edgeMetric.Record(ctx, clientName, serverName) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/mapper/pkg/otelexporter/otel_config.go → .../metricexporter/metric_exporter_config.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package otelexporter | ||
package metricexporter | ||
|
||
import ( | ||
"time" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package metricexporter | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/otterize/network-mapper/src/mapper/pkg/graph/model" | ||
"github.com/otterize/network-mapper/src/mapper/pkg/intentsstore" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type MetricExporterTestSuite struct { | ||
suite.Suite | ||
testNamespace string | ||
intentsHolder *intentsstore.IntentsHolder | ||
edgeMock *MockEdgeMetric | ||
metricExporter *MetricExporter | ||
} | ||
|
||
var ( | ||
testTimestamp = time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC) | ||
) | ||
|
||
func (o *MetricExporterTestSuite) SetupTest() { | ||
o.testNamespace = "default" | ||
o.intentsHolder = intentsstore.NewIntentsHolder() | ||
} | ||
|
||
func (o *MetricExporterTestSuite) BeforeTest(s, testName string) { | ||
controller := gomock.NewController(o.T()) | ||
o.edgeMock = NewMockEdgeMetric(controller) | ||
|
||
metricExporter, _ := NewMetricExporter(context.Background(), Config{ExportInterval: 1 * time.Second}) | ||
metricExporter.edgeMetric = o.edgeMock | ||
o.metricExporter = metricExporter | ||
} | ||
|
||
func (o *MetricExporterTestSuite) addIntent(source string, srcNamespace string, destination string, dstNamespace string) { | ||
o.intentsHolder.AddIntent( | ||
testTimestamp, | ||
model.Intent{ | ||
Client: &model.OtterizeServiceIdentity{Name: source, Namespace: srcNamespace}, | ||
Server: &model.OtterizeServiceIdentity{Name: destination, Namespace: dstNamespace}, | ||
}, | ||
) | ||
} | ||
|
||
func (o *MetricExporterTestSuite) TestExportIntents() { | ||
o.addIntent("client1", o.testNamespace, "server1", o.testNamespace) | ||
o.addIntent("client1", o.testNamespace, "server2", "external-namespace") | ||
o.edgeMock.EXPECT().Record(context.Background(), "client1", "server1").Times(1) | ||
o.edgeMock.EXPECT().Record(context.Background(), "client1", "server2").Times(1) | ||
o.metricExporter.GetIntentCallback(context.Background(), o.intentsHolder.GetNewIntentsSinceLastGet()) | ||
} | ||
|
||
func TestRunSuite(t *testing.T) { | ||
suite.Run(t, new(MetricExporterTestSuite)) | ||
} |
Oops, something went wrong.