-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add Causely destination (#1204)
Adds support for Causely as destination with Traces/Metrics options. --------- Co-authored-by: Amir Blum <amirgiraffe@gmail.com>
- Loading branch information
Showing
10 changed files
with
347 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
| Splunk | ✅ | | | | ||
| Lightstep | ✅ | | | | ||
| Sentry | ✅ | | | | ||
| Causely | ✅ | ✅ | | | ||
|
||
## Open Source | ||
|
||
|
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,98 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"github.com/odigos-io/odigos/common" | ||
"net/url" | ||
"strings" | ||
) | ||
|
||
const ( | ||
causelyUrl = "CAUSELY_URL" | ||
) | ||
|
||
type Causely struct{} | ||
|
||
func (e *Causely) DestType() common.DestinationType { | ||
return common.CauselyDestinationType | ||
} | ||
|
||
func validateCauselyUrlInput(rawUrl string) (string, error) { | ||
urlWithScheme := strings.TrimSpace(rawUrl) | ||
|
||
if !strings.Contains(rawUrl, "://") { | ||
urlWithScheme = "http://" + rawUrl | ||
} | ||
|
||
parsedUrl, err := url.Parse(urlWithScheme) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// Causely does not support paths, so remove it | ||
parsedUrl.Path = "" | ||
|
||
// --- validate the protocol --- | ||
// if scheme is https, convert to "http" (Causely does not currently support TLS export) | ||
if parsedUrl.Scheme == "https" { | ||
parsedUrl.Scheme = "http" | ||
} | ||
// at this point if scheme is not http, it is invalid | ||
if parsedUrl.Scheme != "http" { | ||
return "", fmt.Errorf("Causely endpoint scheme must be http, got %s", parsedUrl.Scheme) | ||
} | ||
|
||
// --- validate host --- | ||
if parsedUrl.Hostname() == "" { | ||
return "", fmt.Errorf("Causely endpoint host is required") | ||
} | ||
|
||
// --- validate port --- | ||
// allow the user specified port, but fallback to Causely default port 4317 if none provided | ||
if parsedUrl.Port() == "" { | ||
parsedUrl.Host = parsedUrl.Hostname() + ":4317" | ||
if err != nil { | ||
return "", err | ||
} | ||
} | ||
|
||
return parsedUrl.String(), nil | ||
} | ||
|
||
func (e *Causely) ModifyConfig(dest ExporterConfigurer, currentConfig *Config) error { | ||
rawUrl, exists := dest.GetConfig()[causelyUrl] | ||
if !exists { | ||
return errors.New("Causely url not specified, gateway will not be configured for Causely") | ||
} | ||
|
||
validatedUrl, err := validateCauselyUrlInput(rawUrl) | ||
if err != nil { | ||
return errors.Join(err, errors.New("failed to parse Causely endpoint, gateway will not be configured for Causely")) | ||
} | ||
|
||
exporterName := "otlp/causely-" + dest.GetName() | ||
|
||
currentConfig.Exporters[exporterName] = GenericMap{ | ||
"endpoint": validatedUrl, | ||
"tls": GenericMap{ | ||
"insecure": true, | ||
}, | ||
} | ||
|
||
if isTracingEnabled(dest) { | ||
tracesPipelineName := "traces/causely-" + dest.GetName() | ||
currentConfig.Service.Pipelines[tracesPipelineName] = Pipeline{ | ||
Exporters: []string{exporterName}, | ||
} | ||
} | ||
|
||
if isMetricsEnabled(dest) { | ||
logsPipelineName := "metrics/causely-" + dest.GetName() | ||
currentConfig.Service.Pipelines[logsPipelineName] = Pipeline{ | ||
Exporters: []string{exporterName}, | ||
} | ||
} | ||
|
||
return nil | ||
} |
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,119 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestCauselyUrlFromInput(t *testing.T) { | ||
type args struct { | ||
rawUrl string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "valid url", | ||
args: args{ | ||
rawUrl: "http://mediator.causely:4317", | ||
}, | ||
want: "http://mediator.causely:4317", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "remove path from url", | ||
args: args{ | ||
rawUrl: "http://mediator.causely:4317/", | ||
}, | ||
want: "http://mediator.causely:4317", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "add http protocol if missing", | ||
args: args{ | ||
rawUrl: "mediator.causely:4317", | ||
}, | ||
want: "http://mediator.causely:4317", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "convert https protocol to http", | ||
args: args{ | ||
rawUrl: "https://mediator.causely:4317", | ||
}, | ||
want: "http://mediator.causely:4317", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "allow only http and https protocols", | ||
args: args{ | ||
rawUrl: "ftp://mediator.causely:4317", | ||
}, | ||
want: "", | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "add default port if missing", | ||
args: args{ | ||
rawUrl: "http://mediator.causely", | ||
}, | ||
want: "http://mediator.causely:4317", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "allow non standard port", | ||
args: args{ | ||
rawUrl: "http://mediator.causely:4567", | ||
}, | ||
want: "http://mediator.causely:4567", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "remove whitespaces", | ||
args: args{ | ||
rawUrl: " http://mediator.causely:4317 ", | ||
}, | ||
want: "http://mediator.causely:4317", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "non numeric port", | ||
args: args{ | ||
rawUrl: "http://mediator.causely:a4317/", | ||
}, | ||
want: "", | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "missing host", | ||
args: args{ | ||
rawUrl: "http://:4317", | ||
}, | ||
want: "", | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "missing host and port", | ||
args: args{ | ||
rawUrl: "http://", | ||
}, | ||
want: "", | ||
wantErr: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := validateCauselyUrlInput(tt.args.rawUrl) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("validateCauselyUrlInput() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if got != tt.want { | ||
t.Errorf("validateCauselyUrlInput() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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,20 @@ | ||
apiVersion: internal.odigos.io/v1beta1 | ||
kind: Destination | ||
metadata: | ||
type: causely | ||
displayName: Causely | ||
category: managed | ||
spec: | ||
image: causely.svg | ||
signals: | ||
traces: | ||
supported: true | ||
metrics: | ||
supported: true | ||
fields: | ||
- name: CAUSELY_URL | ||
displayName: Endpoint | ||
componentType: input | ||
componentProps: | ||
type: text | ||
required: true |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,23 @@ | ||
--- | ||
title: "Causely" | ||
--- | ||
|
||
## Configuring the Causely Backend | ||
|
||
To complete adding a new Causely backend, input the following information into the Odigos UI | ||
|
||
### Causely Destination Settings | ||
|
||
To send Metrics/Traces to Causely, you need to configure the Causely URL in the Odigos UI. | ||
This destination is for the Causely Mediator Service, so you will need to have a Causely instance running and accessible from the k8s cluster running odigos. | ||
|
||
#### Endpoint | ||
|
||
The endpoint URL is the combined `<protocol>://<hostname>:<port>` to access your Causely Mediator service. | ||
|
||
- Protocol should be `http`; using `https` or omitting it will automatically be converted to `http` | ||
- Hostname should typically follow the format: `mediator.<namespace>` | ||
- `namespace` is the k8s namespace where the Causely Mediator service is deployed | ||
- Default port is `4317`; if no port is specified, it will be appended automatically | ||
|
||
Example: `http://mediator.causely:4317` |
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