Skip to content

Commit

Permalink
discovery: Report origin of generated service name (#31226)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitkyrka authored Nov 28, 2024
1 parent 08b90d2 commit cdc6007
Show file tree
Hide file tree
Showing 15 changed files with 749 additions and 604 deletions.
78 changes: 40 additions & 38 deletions pkg/collector/corechecks/servicediscovery/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,26 @@ const (
)

type eventPayload struct {
NamingSchemaVersion string `json:"naming_schema_version"`
ServiceName string `json:"service_name"`
GeneratedServiceName string `json:"generated_service_name"`
DDService string `json:"dd_service,omitempty"`
HostName string `json:"host_name"`
Env string `json:"env"`
ServiceLanguage string `json:"service_language"`
ServiceType string `json:"service_type"`
StartTime int64 `json:"start_time"`
StartTimeMilli int64 `json:"start_time_milli"`
LastSeen int64 `json:"last_seen"`
APMInstrumentation string `json:"apm_instrumentation"`
ServiceNameSource string `json:"service_name_source,omitempty"`
Ports []uint16 `json:"ports"`
PID int `json:"pid"`
CommandLine []string `json:"command_line"`
RSSMemory uint64 `json:"rss_memory"`
CPUCores float64 `json:"cpu_cores"`
ContainerID string `json:"container_id"`
NamingSchemaVersion string `json:"naming_schema_version"`
ServiceName string `json:"service_name"`
GeneratedServiceName string `json:"generated_service_name"`
GeneratedServiceNameSource string `json:"generated_service_name_source,omitempty"`
DDService string `json:"dd_service,omitempty"`
HostName string `json:"host_name"`
Env string `json:"env"`
ServiceLanguage string `json:"service_language"`
ServiceType string `json:"service_type"`
StartTime int64 `json:"start_time"`
StartTimeMilli int64 `json:"start_time_milli"`
LastSeen int64 `json:"last_seen"`
APMInstrumentation string `json:"apm_instrumentation"`
ServiceNameSource string `json:"service_name_source,omitempty"`
Ports []uint16 `json:"ports"`
PID int `json:"pid"`
CommandLine []string `json:"command_line"`
RSSMemory uint64 `json:"rss_memory"`
CPUCores float64 `json:"cpu_cores"`
ContainerID string `json:"container_id"`
}

type event struct {
Expand Down Expand Up @@ -74,25 +75,26 @@ func (ts *telemetrySender) newEvent(t eventType, svc serviceInfo) *event {
RequestType: t,
APIVersion: "v2",
Payload: &eventPayload{
NamingSchemaVersion: "1",
ServiceName: svc.meta.Name,
GeneratedServiceName: svc.service.GeneratedName,
DDService: svc.service.DDService,
HostName: host,
Env: env,
ServiceLanguage: svc.meta.Language,
ServiceType: svc.meta.Type,
StartTime: int64(svc.service.StartTimeMilli / 1000),
StartTimeMilli: int64(svc.service.StartTimeMilli),
LastSeen: svc.LastHeartbeat.Unix(),
APMInstrumentation: svc.meta.APMInstrumentation,
ServiceNameSource: nameSource,
Ports: svc.service.Ports,
PID: svc.service.PID,
CommandLine: svc.service.CommandLine,
RSSMemory: svc.service.RSS,
CPUCores: svc.service.CPUCores,
ContainerID: svc.service.ContainerID,
NamingSchemaVersion: "1",
ServiceName: svc.meta.Name,
GeneratedServiceName: svc.service.GeneratedName,
GeneratedServiceNameSource: svc.service.GeneratedNameSource,
DDService: svc.service.DDService,
HostName: host,
Env: env,
ServiceLanguage: svc.meta.Language,
ServiceType: svc.meta.Type,
StartTime: int64(svc.service.StartTimeMilli / 1000),
StartTimeMilli: int64(svc.service.StartTimeMilli),
LastSeen: svc.LastHeartbeat.Unix(),
APMInstrumentation: svc.meta.APMInstrumentation,
ServiceNameSource: nameSource,
Ports: svc.service.Ports,
PID: svc.service.PID,
CommandLine: svc.service.CommandLine,
RSSMemory: svc.service.RSS,
CPUCores: svc.service.CPUCores,
ContainerID: svc.service.ContainerID,
},
}
}
Expand Down
250 changes: 129 additions & 121 deletions pkg/collector/corechecks/servicediscovery/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,17 @@ func Test_telemetrySender(t *testing.T) {

svc := serviceInfo{
service: model.Service{
PID: 99,
CommandLine: []string{"test-service", "--args"},
Ports: []uint16{80, 8080},
StartTimeMilli: uint64(now.Add(-20 * time.Minute).UnixMilli()),
RSS: 500 * 1024 * 1024,
GeneratedName: "generated-name",
DDService: "dd-service",
DDServiceInjected: true,
CPUCores: 1.5,
ContainerID: "abcd",
PID: 99,
CommandLine: []string{"test-service", "--args"},
Ports: []uint16{80, 8080},
StartTimeMilli: uint64(now.Add(-20 * time.Minute).UnixMilli()),
RSS: 500 * 1024 * 1024,
GeneratedName: "generated-name",
GeneratedNameSource: "generated-name-source",
DDService: "dd-service",
DDServiceInjected: true,
CPUCores: 1.5,
ContainerID: "abcd",
},
meta: ServiceMetadata{
Name: "test-service",
Expand All @@ -85,75 +86,78 @@ func Test_telemetrySender(t *testing.T) {
RequestType: "start-service",
APIVersion: "v2",
Payload: &eventPayload{
NamingSchemaVersion: "1",
ServiceName: "test-service",
GeneratedServiceName: "generated-name",
DDService: "dd-service",
ServiceNameSource: "injected",
HostName: "test-host",
Env: "",
ServiceLanguage: "jvm",
ServiceType: "web_service",
StartTime: 1715557200,
StartTimeMilli: 1715557200 * 1000,
LastSeen: 1715558400,
APMInstrumentation: "injected",
Ports: []uint16{80, 8080},
PID: 99,
CommandLine: []string{"test-service", "--args"},
RSSMemory: 500 * 1024 * 1024,
CPUCores: 1.5,
ContainerID: "abcd",
NamingSchemaVersion: "1",
ServiceName: "test-service",
GeneratedServiceName: "generated-name",
GeneratedServiceNameSource: "generated-name-source",
DDService: "dd-service",
ServiceNameSource: "injected",
HostName: "test-host",
Env: "",
ServiceLanguage: "jvm",
ServiceType: "web_service",
StartTime: 1715557200,
StartTimeMilli: 1715557200 * 1000,
LastSeen: 1715558400,
APMInstrumentation: "injected",
Ports: []uint16{80, 8080},
PID: 99,
CommandLine: []string{"test-service", "--args"},
RSSMemory: 500 * 1024 * 1024,
CPUCores: 1.5,
ContainerID: "abcd",
},
},
{
RequestType: "heartbeat-service",
APIVersion: "v2",
Payload: &eventPayload{
NamingSchemaVersion: "1",
ServiceName: "test-service",
GeneratedServiceName: "generated-name",
DDService: "dd-service",
ServiceNameSource: "injected",
HostName: "test-host",
Env: "",
ServiceLanguage: "jvm",
ServiceType: "web_service",
StartTime: 1715557200,
StartTimeMilli: 1715557200 * 1000,
LastSeen: 1715558400,
APMInstrumentation: "injected",
Ports: []uint16{80, 8080},
PID: 99,
CommandLine: []string{"test-service", "--args"},
RSSMemory: 500 * 1024 * 1024,
CPUCores: 1.5,
ContainerID: "abcd",
NamingSchemaVersion: "1",
ServiceName: "test-service",
GeneratedServiceName: "generated-name",
GeneratedServiceNameSource: "generated-name-source",
DDService: "dd-service",
ServiceNameSource: "injected",
HostName: "test-host",
Env: "",
ServiceLanguage: "jvm",
ServiceType: "web_service",
StartTime: 1715557200,
StartTimeMilli: 1715557200 * 1000,
LastSeen: 1715558400,
APMInstrumentation: "injected",
Ports: []uint16{80, 8080},
PID: 99,
CommandLine: []string{"test-service", "--args"},
RSSMemory: 500 * 1024 * 1024,
CPUCores: 1.5,
ContainerID: "abcd",
},
},
{
RequestType: "end-service",
APIVersion: "v2",
Payload: &eventPayload{
NamingSchemaVersion: "1",
ServiceName: "test-service",
GeneratedServiceName: "generated-name",
DDService: "dd-service",
ServiceNameSource: "injected",
HostName: "test-host",
Env: "",
ServiceLanguage: "jvm",
ServiceType: "web_service",
StartTime: 1715557200,
StartTimeMilli: 1715557200 * 1000,
LastSeen: 1715558400,
APMInstrumentation: "injected",
Ports: []uint16{80, 8080},
PID: 99,
CommandLine: []string{"test-service", "--args"},
RSSMemory: 500 * 1024 * 1024,
CPUCores: 1.5,
ContainerID: "abcd",
NamingSchemaVersion: "1",
ServiceName: "test-service",
GeneratedServiceName: "generated-name",
GeneratedServiceNameSource: "generated-name-source",
DDService: "dd-service",
ServiceNameSource: "injected",
HostName: "test-host",
Env: "",
ServiceLanguage: "jvm",
ServiceType: "web_service",
StartTime: 1715557200,
StartTimeMilli: 1715557200 * 1000,
LastSeen: 1715558400,
APMInstrumentation: "injected",
Ports: []uint16{80, 8080},
PID: 99,
CommandLine: []string{"test-service", "--args"},
RSSMemory: 500 * 1024 * 1024,
CPUCores: 1.5,
ContainerID: "abcd",
},
},
}
Expand Down Expand Up @@ -184,12 +188,13 @@ func Test_telemetrySender_name_provided(t *testing.T) {

svc := serviceInfo{
service: model.Service{
PID: 55,
CommandLine: []string{"foo", "--option"},
StartTimeMilli: uint64(now.Add(-20 * time.Minute).UnixMilli()),
GeneratedName: "generated-name2",
DDService: "dd-service-provided",
ContainerID: "abcd",
PID: 55,
CommandLine: []string{"foo", "--option"},
StartTimeMilli: uint64(now.Add(-20 * time.Minute).UnixMilli()),
GeneratedName: "generated-name2",
GeneratedNameSource: "generated-name-source2",
DDService: "dd-service-provided",
ContainerID: "abcd",
},
meta: ServiceMetadata{
Name: "test-service",
Expand All @@ -209,66 +214,69 @@ func Test_telemetrySender_name_provided(t *testing.T) {
RequestType: "start-service",
APIVersion: "v2",
Payload: &eventPayload{
NamingSchemaVersion: "1",
ServiceName: "test-service",
GeneratedServiceName: "generated-name2",
DDService: "dd-service-provided",
ServiceNameSource: "provided",
HostName: "test-host",
Env: "",
ServiceLanguage: "jvm",
ServiceType: "web_service",
StartTime: 1715557200,
StartTimeMilli: 1715557200 * 1000,
LastSeen: 1715558400,
APMInstrumentation: "injected",
PID: 55,
CommandLine: []string{"foo", "--option"},
ContainerID: "abcd",
NamingSchemaVersion: "1",
ServiceName: "test-service",
GeneratedServiceName: "generated-name2",
GeneratedServiceNameSource: "generated-name-source2",
DDService: "dd-service-provided",
ServiceNameSource: "provided",
HostName: "test-host",
Env: "",
ServiceLanguage: "jvm",
ServiceType: "web_service",
StartTime: 1715557200,
StartTimeMilli: 1715557200 * 1000,
LastSeen: 1715558400,
APMInstrumentation: "injected",
PID: 55,
CommandLine: []string{"foo", "--option"},
ContainerID: "abcd",
},
},
{
RequestType: "heartbeat-service",
APIVersion: "v2",
Payload: &eventPayload{
NamingSchemaVersion: "1",
ServiceName: "test-service",
GeneratedServiceName: "generated-name2",
DDService: "dd-service-provided",
ServiceNameSource: "provided",
HostName: "test-host",
Env: "",
ServiceLanguage: "jvm",
ServiceType: "web_service",
StartTime: 1715557200,
StartTimeMilli: 1715557200 * 1000,
LastSeen: 1715558400,
APMInstrumentation: "injected",
PID: 55,
CommandLine: []string{"foo", "--option"},
ContainerID: "abcd",
NamingSchemaVersion: "1",
ServiceName: "test-service",
GeneratedServiceName: "generated-name2",
GeneratedServiceNameSource: "generated-name-source2",
DDService: "dd-service-provided",
ServiceNameSource: "provided",
HostName: "test-host",
Env: "",
ServiceLanguage: "jvm",
ServiceType: "web_service",
StartTime: 1715557200,
StartTimeMilli: 1715557200 * 1000,
LastSeen: 1715558400,
APMInstrumentation: "injected",
PID: 55,
CommandLine: []string{"foo", "--option"},
ContainerID: "abcd",
},
},
{
RequestType: "end-service",
APIVersion: "v2",
Payload: &eventPayload{
NamingSchemaVersion: "1",
ServiceName: "test-service",
GeneratedServiceName: "generated-name2",
DDService: "dd-service-provided",
ServiceNameSource: "provided",
HostName: "test-host",
Env: "",
ServiceLanguage: "jvm",
ServiceType: "web_service",
StartTime: 1715557200,
StartTimeMilli: 1715557200 * 1000,
LastSeen: 1715558400,
APMInstrumentation: "injected",
PID: 55,
CommandLine: []string{"foo", "--option"},
ContainerID: "abcd",
NamingSchemaVersion: "1",
ServiceName: "test-service",
GeneratedServiceName: "generated-name2",
GeneratedServiceNameSource: "generated-name-source2",
DDService: "dd-service-provided",
ServiceNameSource: "provided",
HostName: "test-host",
Env: "",
ServiceLanguage: "jvm",
ServiceType: "web_service",
StartTime: 1715557200,
StartTimeMilli: 1715557200 * 1000,
LastSeen: 1715558400,
APMInstrumentation: "injected",
PID: 55,
CommandLine: []string{"foo", "--option"},
ContainerID: "abcd",
},
},
}
Expand Down
Loading

0 comments on commit cdc6007

Please sign in to comment.