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

Emit map as an OpenTelemetry metric #141

Merged
merged 31 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ae7e254
emit edges as OTLP metrics
smithclay Sep 22, 2023
22c779e
emit metric to stdout when debug mode is enabled
smithclay Sep 25, 2023
c3fddd9
use otel library version semconv
smithclay Sep 25, 2023
5c75cfe
add test scaffold
smithclay Sep 25, 2023
2cc4f3c
config and shutdown cleanup
smithclay Oct 2, 2023
cf4f4ae
use callbacks, add tests
smithclay Oct 3, 2023
52a0257
config cleanup
smithclay Oct 3, 2023
96eac06
allow metric name to be over-ridden
smithclay Oct 3, 2023
7ce6d7f
pr feedback
smithclay Oct 3, 2023
1b785f5
Fix fork build pipeline
orishoshan Oct 6, 2023
a74e512
Merge branch 'main' into add-otel-exporter
orishoshan Oct 6, 2023
c4dd700
Fix fork build pipeline
orishoshan Oct 6, 2023
375b75f
Merge branch 'main' into add-otel-exporter
orishoshan Oct 6, 2023
49959c9
Fix fork build pipeline
orishoshan Oct 6, 2023
61a0983
Merge branch 'main' into add-otel-exporter
orishoshan Oct 6, 2023
ec60533
Fix fork build pipeline
orishoshan Oct 6, 2023
45da3a9
Merge branch 'main' into add-otel-exporter
orishoshan Oct 6, 2023
f184a44
Fix fork build pipeline
orishoshan Oct 6, 2023
8ba8d0d
Merge branch 'main' into add-otel-exporter
orishoshan Oct 6, 2023
82fdd94
Fix fork build pipeline
orishoshan Oct 6, 2023
28d7a40
Merge branch 'main' into add-otel-exporter
orishoshan Oct 6, 2023
28d25bd
Fix fork build pipeline
orishoshan Oct 6, 2023
d38da8d
Merge branch 'main' into add-otel-exporter
orishoshan Oct 6, 2023
054263f
Fix fork build pipeline
orishoshan Oct 6, 2023
1c370d6
Merge branch 'main' into add-otel-exporter
orishoshan Oct 6, 2023
660a5ff
Merge branch 'main' into add-otel-exporter
orishoshan Oct 6, 2023
b30cddb
Merge branch 'main' into add-otel-exporter
orishoshan Oct 16, 2023
e6f6fa1
go mod tidy
smithclay Oct 16, 2023
4207d23
Merge branch 'main' into add-otel-exporter
orishoshan Oct 18, 2023
d134451
Merge branch 'main' into add-otel-exporter
orishoshan Oct 18, 2023
37ef89d
go mod tidy
orishoshan Oct 18, 2023
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
1 change: 0 additions & 1 deletion .github/workflows/e2e-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ on:
default: us-central1-docker.pkg.dev/main-383408/otterize



env:
REGISTRY: ${{ inputs.registry }}

Expand Down
25 changes: 20 additions & 5 deletions src/go.mod

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

54 changes: 43 additions & 11 deletions src/go.sum

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

27 changes: 20 additions & 7 deletions src/mapper/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ package main
import (
"context"
"fmt"
"net/http"
"os"
"os/signal"
"syscall"
"time"

"github.com/google/uuid"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
Expand All @@ -14,6 +20,7 @@ import (
"github.com/otterize/network-mapper/src/mapper/pkg/config"
"github.com/otterize/network-mapper/src/mapper/pkg/intentsstore"
"github.com/otterize/network-mapper/src/mapper/pkg/kubefinder"
"github.com/otterize/network-mapper/src/mapper/pkg/metricexporter"
"github.com/otterize/network-mapper/src/mapper/pkg/resolvers"
sharedconfig "github.com/otterize/network-mapper/src/shared/config"
"github.com/otterize/network-mapper/src/shared/kubeutils"
Expand All @@ -23,14 +30,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/metadata"
"net/http"
"os"
"os/signal"
clientconfig "sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
"syscall"
"time"
)

func getClusterDomainOrDefault() string {
Expand Down Expand Up @@ -117,13 +119,24 @@ func main() {
if err != nil {
logrus.WithError(err).Fatal("Failed to initialize cloud client")
}

cloudUploaderConfig := clouduploader.ConfigFromViper()
if cloudEnabled {
cloudUploaderConfig := clouduploader.ConfigFromViper()
cloudUploader := clouduploader.NewCloudUploader(intentsHolder, cloudUploaderConfig, cloudClient)
go cloudUploader.PeriodicIntentsUpload(cloudClientCtx)
intentsHolder.RegisterGetCallback(cloudUploader.GetIntentCallback)
go cloudUploader.PeriodicStatusReport(cloudClientCtx)
}

if viper.GetBool(config.OTelEnabledKey) {
otelExporter, err := metricexporter.NewMetricExporter(cloudClientCtx)
intentsHolder.RegisterGetCallback(otelExporter.GetIntentCallback)
if err != nil {
logrus.WithError(err).Fatal("Failed to initialize otel exporter")
}
}

go intentsHolder.PeriodicIntentsUpload(cloudClientCtx, cloudUploaderConfig.UploadInterval)

telemetrysender.SetGlobalVersion(version.Version())
telemetrysender.SendNetworkMapper(telemetriesgql.EventTypeStarted, 1)
logrus.Info("Starting api server")
Expand Down
21 changes: 4 additions & 17 deletions src/mapper/pkg/clouduploader/cloud_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package clouduploader

import (
"context"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/otterize/network-mapper/src/mapper/pkg/cloudclient"
"github.com/otterize/network-mapper/src/mapper/pkg/graph/model"
"github.com/otterize/network-mapper/src/mapper/pkg/intentsstore"
"github.com/samber/lo"
"github.com/sirupsen/logrus"
"time"
)

type CloudUploader struct {
Expand All @@ -25,10 +26,10 @@ func NewCloudUploader(intentsHolder *intentsstore.IntentsHolder, config Config,
}
}

func (c *CloudUploader) uploadDiscoveredIntents(ctx context.Context) {
func (c *CloudUploader) GetIntentCallback(ctx context.Context, intents []intentsstore.TimestampedIntent) {
logrus.Info("Search for intents")

discoveredIntents := lo.Map(c.intentsHolder.GetNewIntentsSinceLastGet(), func(intent intentsstore.TimestampedIntent, _ int) *cloudclient.DiscoveredIntentInput {
discoveredIntents := lo.Map(intents, func(intent intentsstore.TimestampedIntent, _ int) *cloudclient.DiscoveredIntentInput {
return &cloudclient.DiscoveredIntentInput{
DiscoveredAt: lo.ToPtr(intent.Timestamp),
Intent: &cloudclient.IntentInput{
Expand Down Expand Up @@ -90,20 +91,6 @@ func (c *CloudUploader) reportStatus(ctx context.Context) {
}
}

func (c *CloudUploader) PeriodicIntentsUpload(ctx context.Context) {
logrus.Info("Starting periodic intents upload")

for {
select {
case <-time.After(c.config.UploadInterval):
c.uploadDiscoveredIntents(ctx)

case <-ctx.Done():
return
}
}
}

func (c *CloudUploader) PeriodicStatusReport(ctx context.Context) {
logrus.Info("Starting status reporting")
c.reportStatus(ctx)
Expand Down
Loading
Loading