Skip to content

Commit

Permalink
Use the operator unique counter for telemetries (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
NetanelBollag authored Oct 2, 2023
1 parent c49bbb1 commit dfdd4ff
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 60 deletions.
18 changes: 9 additions & 9 deletions src/go.mod

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

37 changes: 18 additions & 19 deletions src/go.sum

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

1 change: 0 additions & 1 deletion src/mapper/pkg/cloudclient/generated.go

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

10 changes: 0 additions & 10 deletions src/mapper/pkg/cloudclient/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -775,16 +775,6 @@ type Query {
clusterId: ID
name: String
): Integration!
"""Get intent"""
intent(
id: ID!
): Intent!
"""List intents"""
intents(
environmentId: ID
clientId: ID
serverId: ID
): [Intent!]!
"""Get namespace"""
namespace(
id: ID!
Expand Down
7 changes: 0 additions & 7 deletions src/mapper/pkg/intentsstore/holder.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,6 @@ func (i *IntentsHolder) GetIntents(
return result, nil
}

func (i *IntentsHolder) GetIntentsCount() int {
i.lock.Lock()
defer i.lock.Unlock()

return len(i.accumulatingStore)
}

func (i *IntentsHolder) GetNewIntentsSinceLastGet() []TimestampedIntent {
i.lock.Lock()
defer i.lock.Unlock()
Expand Down
39 changes: 39 additions & 0 deletions src/mapper/pkg/resolvers/schema.helpers.resolvers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package resolvers

import (
"fmt"
"github.com/otterize/intents-operator/src/shared/telemetries/telemetriesgql"
"github.com/otterize/intents-operator/src/shared/telemetries/telemetrysender"
"github.com/otterize/network-mapper/src/mapper/pkg/graph/model"
"github.com/sirupsen/logrus"
)

type SourceType string

const (
SourceTypeDNSCapture SourceType = "Capture"
SourceTypeSocketScan SourceType = "SocketScan"
SourceTypeKafkaMapper SourceType = "KafkaMapper"
SourceTypeIstio SourceType = "Istio"
)

func updateTelemetriesCounters(sourceType SourceType, intent model.Intent) {
clientKey := telemetrysender.Anonymize(fmt.Sprintf("%s/%s", intent.Client.Namespace, intent.Client.Name))
serverKey := telemetrysender.Anonymize(fmt.Sprintf("%s/%s", intent.Server.Namespace, intent.Server.Name))
intentKey := telemetrysender.Anonymize(fmt.Sprintf("%s-%s", clientKey, serverKey))

telemetrysender.IncrementUniqueCounterNetworkMapper(telemetriesgql.EventTypeIntentsDiscovered, intentKey)
telemetrysender.IncrementUniqueCounterNetworkMapper(telemetriesgql.EventTypeServiceDiscovered, clientKey)
telemetrysender.IncrementUniqueCounterNetworkMapper(telemetriesgql.EventTypeServiceDiscovered, serverKey)

logrus.Infof("Discovered intent %s, %s, %s", clientKey, serverKey, intentKey)
if sourceType == SourceTypeDNSCapture {
telemetrysender.IncrementUniqueCounterNetworkMapper(telemetriesgql.EventTypeIntentsDiscoveredCapture, intentKey)
} else if sourceType == SourceTypeSocketScan {
telemetrysender.IncrementUniqueCounterNetworkMapper(telemetriesgql.EventTypeIntentsDiscoveredSocketScan, intentKey)
} else if sourceType == SourceTypeKafkaMapper {
telemetrysender.IncrementUniqueCounterNetworkMapper(telemetriesgql.EventTypeIntentsDiscoveredKafka, intentKey)
} else if sourceType == SourceTypeIstio {
telemetrysender.IncrementUniqueCounterNetworkMapper(telemetriesgql.EventTypeIntentsDiscoveredIstio, intentKey)
}
}
22 changes: 10 additions & 12 deletions src/mapper/pkg/resolvers/schema.resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"errors"
"strings"

"github.com/otterize/intents-operator/src/shared/telemetries/telemetriesgql"
"github.com/otterize/intents-operator/src/shared/telemetries/telemetrysender"
"github.com/otterize/network-mapper/src/mapper/pkg/config"
"github.com/otterize/network-mapper/src/mapper/pkg/graph/generated"
"github.com/otterize/network-mapper/src/mapper/pkg/graph/model"
Expand Down Expand Up @@ -86,16 +84,16 @@ func (r *mutationResolver) ReportCaptureResults(ctx context.Context, results mod
Server: dstSvcIdentity,
}

updateTelemetriesCounters(SourceTypeDNSCapture, intent)
r.intentsHolder.AddIntent(
dest.LastSeen,
intent,
)
newResults++
}
}

prometheus.IncrementDNSCaptureReports(newResults)
telemetrysender.SendNetworkMapper(telemetriesgql.EventTypeIntentsDiscoveredCapture, newResults)
telemetrysender.SendNetworkMapper(telemetriesgql.EventTypeIntentsDiscovered, r.intentsHolder.GetIntentsCount())
return true, nil
}

Expand Down Expand Up @@ -143,6 +141,7 @@ func (r *mutationResolver) ReportSocketScanResults(ctx context.Context, results
Server: dstSvcIdentity,
}

updateTelemetriesCounters(SourceTypeSocketScan, intent)
r.intentsHolder.AddIntent(
destIp.LastSeen,
intent,
Expand All @@ -151,8 +150,6 @@ func (r *mutationResolver) ReportSocketScanResults(ctx context.Context, results
}
}
prometheus.IncrementSocketScanReports(newResults)
telemetrysender.SendNetworkMapper(telemetriesgql.EventTypeIntentsDiscoveredSocketScan, newResults)
telemetrysender.SendNetworkMapper(telemetriesgql.EventTypeIntentsDiscovered, r.intentsHolder.GetIntentsCount())
return true, nil
}

Expand Down Expand Up @@ -217,6 +214,7 @@ func (r *mutationResolver) ReportKafkaMapperResults(ctx context.Context, results
},
}

updateTelemetriesCounters(SourceTypeKafkaMapper, intent)
r.intentsHolder.AddIntent(
result.LastSeen,
intent,
Expand All @@ -225,8 +223,6 @@ func (r *mutationResolver) ReportKafkaMapperResults(ctx context.Context, results
}

prometheus.IncrementKafkaReports(newResults)
telemetrysender.SendNetworkMapper(telemetriesgql.EventTypeIntentsDiscoveredKafka, newResults)
telemetrysender.SendNetworkMapper(telemetriesgql.EventTypeIntentsDiscovered, r.intentsHolder.GetIntentsCount())
return true, nil
}

Expand Down Expand Up @@ -263,18 +259,20 @@ func (r *mutationResolver) ReportIstioConnectionResults(ctx context.Context, res
if dstService.OwnerObject != nil {
dstSvcIdentity.PodOwnerKind = model.GroupVersionKindFromKubeGVK(dstService.OwnerObject.GetObjectKind().GroupVersionKind())
}
r.intentsHolder.AddIntent(result.LastSeen, model.Intent{

intent := model.Intent{
Client: &srcSvcIdentity,
Server: &dstSvcIdentity,
Type: lo.ToPtr(model.IntentTypeHTTP),
HTTPResources: []model.HTTPResource{{Path: result.Path, Methods: result.Methods}},
})
}

updateTelemetriesCounters(SourceTypeIstio, intent)
r.intentsHolder.AddIntent(result.LastSeen, intent)
newResults++
}

prometheus.IncrementIstioReports(newResults)
telemetrysender.SendNetworkMapper(telemetriesgql.EventTypeIntentsDiscoveredIstio, newResults)
telemetrysender.SendNetworkMapper(telemetriesgql.EventTypeIntentsDiscovered, r.intentsHolder.GetIntentsCount())
return true, nil
}

Expand Down
3 changes: 1 addition & 2 deletions src/mapper/pkg/resolvers/test_gql_client/generated.go

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

0 comments on commit dfdd4ff

Please sign in to comment.