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

feat:Elasticsearch destination #1412

Merged
merged 17 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
53 changes: 31 additions & 22 deletions frontend/endpoints/destination_recognition/destination_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ package destination_recognition

import (
"github.com/gin-gonic/gin"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/frontend/kube"
"github.com/odigos-io/odigos/k8sutils/pkg/client"
k8s "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type DestinationType string

const (
JaegerDestinationType DestinationType = "jaeger"
)

var SupportedDestinationType = []DestinationType{JaegerDestinationType}
var SupportedDestinationType = []common.DestinationType{common.JaegerDestinationType, common.ElasticsearchDestinationType}

type DestinationDetails struct {
Name string `json:"name"`
Expand All @@ -36,32 +34,43 @@ func (d *DestinationFinder) fetchDestinationDetails(service k8s.Service) Destina
}

func GetAllPotentialDestinationDetails(ctx *gin.Context, namespaces []k8s.Namespace) ([]DestinationDetails, error) {
helmManagedServices, err := getAllHelmManagedServices(ctx, namespaces)
if err != nil {
return nil, err
}

var destinationFinder *DestinationFinder
var destinationDetails []DestinationDetails
for _, service := range helmManagedServices {
for _, destinationType := range SupportedDestinationType {
destinationFinder = getDestinationFinder(destinationType)
if destinationFinder.isPotentialService(service) {
destinationDetails = append(destinationDetails, destinationFinder.fetchDestinationDetails(service))
break
}
}
var err error

for _, ns := range namespaces {
err = client.ListWithPages(client.DefaultPageSize, kube.DefaultClient.CoreV1().Services(ns.Name).List,
ctx, metav1.ListOptions{}, func(services *k8s.ServiceList) error {
for _, service := range services.Items {
for _, destinationType := range SupportedDestinationType {
destinationFinder = getDestinationFinder(destinationType)
if destinationFinder.isPotentialService(service) {
destinationDetails = append(destinationDetails, destinationFinder.fetchDestinationDetails(service))
break
}
}
}
return nil
})
}

if err != nil {
return nil, err
}

return destinationDetails, nil
}

func getDestinationFinder(destinationType DestinationType) *DestinationFinder {
func getDestinationFinder(destinationType common.DestinationType) *DestinationFinder {
switch destinationType {
case JaegerDestinationType:
case common.JaegerDestinationType:
return &DestinationFinder{
destinationFinder: &JaegerDestinationFinder{},
}
case common.ElasticsearchDestinationType:
return &DestinationFinder{
destinationFinder: &ElasticSearchDestinationFinder{},
}
}

return nil
Expand Down
35 changes: 35 additions & 0 deletions frontend/endpoints/destination_recognition/elasticsearch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package destination_recognition

import (
"fmt"
"github.com/odigos-io/odigos/common"
k8s "k8s.io/api/core/v1"
"strings"
)

type ElasticSearchDestinationFinder struct{}

const ElasticSearchHttpPort int32 = 9200
const ElasticSearchHttpUrlFormat = "https://%s.%s:%d"

func (j *ElasticSearchDestinationFinder) isPotentialService(service k8s.Service) bool {
for _, port := range service.Spec.Ports {
if isElasticSearchService(port.Port, service.Name) {
return true
}
}

return false
}

func isElasticSearchService(portNumber int32, name string) bool {
return portNumber == ElasticSearchHttpPort && strings.Contains(name, string(common.ElasticsearchDestinationType))
}

func (j *ElasticSearchDestinationFinder) fetchDestinationDetails(service k8s.Service) DestinationDetails {
urlString := fmt.Sprintf(ElasticSearchHttpUrlFormat, service.Name, service.Namespace, ElasticSearchHttpPort)
return DestinationDetails{
Name: string(common.ElasticsearchDestinationType),
UrlString: urlString,
}
}
42 changes: 0 additions & 42 deletions frontend/endpoints/destination_recognition/utils.go

This file was deleted.

Loading