-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat remove subdomain telemetry merge gitlab attempt (#563)
* feat: filter subdomains in telemetry Signed-off-by: João Vanzuita <joao@kubeshop.io>
- Loading branch information
João Paulo Vanzuita
authored
Oct 14, 2022
1 parent
55adca1
commit 0669de2
Showing
8 changed files
with
354 additions
and
72 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
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,33 @@ | ||
package domain | ||
|
||
import ( | ||
"errors" | ||
"github.com/kubefirst/kubefirst/pkg" | ||
) | ||
|
||
// Telemetry data that will be consumed by handlers and services | ||
type Telemetry struct { | ||
MetricName string | ||
Domain string | ||
CLIVersion string | ||
} | ||
|
||
// NewTelemetry is the Telemetry domain. When instantiating new Telemetries, we're able to validate domain specific | ||
// values. In this way, domain, handlers and services can work in isolation, and Domain host business logic. | ||
func NewTelemetry(metricName string, domain string, CLIVersion string) (*Telemetry, error) { | ||
|
||
if len(metricName) == 0 { | ||
return nil, errors.New("unable to create metric, missing metric name") | ||
} | ||
|
||
domain, err := pkg.RemoveSubDomain(domain) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Telemetry{ | ||
MetricName: metricName, | ||
Domain: domain, | ||
CLIVersion: CLIVersion, | ||
}, 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,76 @@ | ||
package domain | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestNewTelemetry(t *testing.T) { | ||
|
||
validTelemetry := Telemetry{MetricName: "test metric", Domain: "example.com", CLIVersion: "0.0.0"} | ||
|
||
type args struct { | ||
metricName string | ||
domain string | ||
CLIVersion string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *Telemetry | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "valid domain", | ||
args: args{ | ||
metricName: "test metric", | ||
domain: "https://example.com", | ||
CLIVersion: "0.0.0", | ||
}, | ||
want: &validTelemetry, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "invalid domain", | ||
args: args{ | ||
metricName: "test metric", | ||
domain: "https://example-com", | ||
CLIVersion: "0.0.0", | ||
}, | ||
want: nil, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "empty domain", | ||
args: args{ | ||
metricName: "test metric", | ||
domain: "", | ||
CLIVersion: "0.0.0", | ||
}, | ||
want: nil, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "missing telemetry name", | ||
args: args{ | ||
metricName: "", | ||
domain: "example.com", | ||
CLIVersion: "0.0.0", | ||
}, | ||
want: nil, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := NewTelemetry(tt.args.metricName, tt.args.domain, tt.args.CLIVersion) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("NewTelemetry() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("NewTelemetry() got = %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
Oops, something went wrong.