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

[v14] Add Posthog events for discovered Kubernetes Apps #32379

Merged
merged 1 commit into from
Sep 25, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions api/gen/proto/go/usageevents/v1/usageevents.pb.go

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

7 changes: 4 additions & 3 deletions api/proto/teleport/usageevents/v1/usageevents.proto
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,12 @@ message UIIntegrationEnrollCompleteEvent {

// ResourceCreateEvent is emitted when a resource is created.
message ResourceCreateEvent {
// resource_type is the type of resource ("node", "node.openssh", "db", "k8s").
// resource_type is the type of resource ("node", "node.openssh", "db", "k8s", "app").
string resource_type = 1;
// resource_origin is the origin of the resource ("cloud").
// resource_origin is the origin of the resource ("cloud", "kubernetes").
string resource_origin = 2;
// cloud_provider is the cloud provider the resource came from ("AWS", "Azure", "GCP").
// cloud_provider is the cloud provider the resource came from ("AWS", "Azure", "GCP")
// if resource_origin == "cloud".
string cloud_provider = 3;
// database contains additional database information if resource_type == "db".
DiscoveredDatabaseMetadata database = 4;
Expand Down
2 changes: 2 additions & 0 deletions api/types/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,8 @@ const (
DiscoveredResourceKubernetes = "k8s"
// DiscoveredResourceAgentlessNode identifies a discovered agentless SSH node.
DiscoveredResourceAgentlessNode = "node.openssh"
// DiscoveredResourceApp identifies a discovered Kubernetes App.
DiscoveredResourceApp = "app"

// TeleportAzureMSIEndpoint is a special URL intercepted by TSH local proxy, serving Azure credentials.
TeleportAzureMSIEndpoint = "azure-msi." + TeleportNamespace
Expand Down
7 changes: 4 additions & 3 deletions gen/proto/go/prehog/v1alpha/teleport.pb.go

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

18 changes: 17 additions & 1 deletion lib/srv/discovery/kube_services_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ import (

"github.com/gravitational/trace"

usageeventsv1 "github.com/gravitational/teleport/api/gen/proto/go/usageevents/v1"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/services"
"github.com/gravitational/teleport/lib/srv/discovery/common"
)

const appEventPrefix = "app/"

func (s *Server) startKubeAppsWatchers() error {
if len(s.kubeAppsFetchers) == 0 {
return nil
Expand Down Expand Up @@ -113,7 +116,20 @@ func (s *Server) onAppCreate(ctx context.Context, rwl types.ResourceWithLabels)
if trace.IsAlreadyExists(err) {
return trace.Wrap(s.onAppUpdate(ctx, rwl))
}
return trace.Wrap(err)
if err != nil {
return trace.Wrap(err)
}
err = s.emitUsageEvents(map[string]*usageeventsv1.ResourceCreateEvent{
appEventPrefix + app.GetName(): {
ResourceType: types.DiscoveredResourceApp,
ResourceOrigin: types.OriginKubernetes,
// CloudProvider is not set for apps created from Kubernetes services
},
})
if err != nil {
s.Log.WithError(err).Debug("Error emitting usage event.")
}
return nil
}

func (s *Server) onAppUpdate(ctx context.Context, rwl types.ResourceWithLabels) error {
Expand Down
7 changes: 4 additions & 3 deletions proto/prehog/v1alpha/teleport.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ message SSOCreateEvent {

// ResourceCreateEvent is emitted when a resource is created.
message ResourceCreateEvent {
// resource_type is the type of resource ("node", "node.openssh", "db", "k8s").
// resource_type is the type of resource ("node", "node.openssh", "db", "k8s", "app").
string resource_type = 1;
// resource_origin is the origin of the resource ("cloud").
// resource_origin is the origin of the resource ("cloud", "kubernetes").
string resource_origin = 2;
// cloud_provider is the cloud provider the resource came from ("AWS", "Azure", "GCP").
// cloud_provider is the cloud provider the resource came from ("AWS", "Azure", "GCP")
// if resource_origin == "cloud".
string cloud_provider = 3;
// database contains additional database information if resource_type == "db".
DiscoveredDatabaseMetadata database = 4;
Expand Down