Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
VladislavSenkevich committed Oct 28, 2024
1 parent 85fb119 commit a052643
Showing 1 changed file with 44 additions and 33 deletions.
77 changes: 44 additions & 33 deletions connectors/databricks/databricks.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,45 +78,56 @@ func getJobsResources(databricksClient *client.DatabricksClient, from time.Time,
var services []transit.MonitoredService
for _, runs := range jobsRuns {
if len(runs) > 0 {
var metricBuilders []connectors.MetricBuilder
for _, run := range runs {
if !slices.Contains([]string{"QUEUED", "PENDING", "RUNNING", "TERMINATING"}, run.Status.State) {
metricBuilders = append(metricBuilders, []connectors.MetricBuilder{
{
Name: "latency_seconds",
CustomName: "latency_seconds",
Value: 1.0,
Graphed: true,
StartTimestamp: &transit.Timestamp{Time: time.UnixMilli(run.StartTime).Add(-(2 * time.Minute))},
EndTimestamp: &transit.Timestamp{Time: time.UnixMilli(run.StartTime).Add(-time.Minute)},
},
{
Name: "latency_seconds",
CustomName: "latency_seconds",
Value: run.RunDuration / 1000,
Graphed: true,
StartTimestamp: &transit.Timestamp{Time: time.UnixMilli(run.StartTime)},
EndTimestamp: &transit.Timestamp{Time: time.UnixMilli(run.EndTime)},
},
{
Name: "latency_seconds",
CustomName: "latency_seconds",
Value: 1.0,
Graphed: true,
StartTimestamp: &transit.Timestamp{Time: time.UnixMilli(run.EndTime).Add(time.Minute)},
EndTimestamp: &transit.Timestamp{Time: time.UnixMilli(run.EndTime).Add(2 * time.Minute)},
},
}...)
service0, err := connectors.BuildServiceForMetric(hostName, connectors.MetricBuilder{
Name: "latency_seconds",
CustomName: "latency_seconds",
Value: 0,
Graphed: true,
StartTimestamp: &transit.Timestamp{Time: time.UnixMilli(run.StartTime)},
EndTimestamp: &transit.Timestamp{Time: time.UnixMilli(run.EndTime)},
})
if err != nil {
log.Error().Err(err).Str("job_name", run.RunName).Msg("failed to build service for metric")
continue
}
service0.Name = run.RunName

metricBuilder := connectors.MetricBuilder{
Name: "latency_seconds",
CustomName: "latency_seconds",
Value: run.RunDuration / 1000,
Graphed: true,
StartTimestamp: &transit.Timestamp{Time: time.UnixMilli(run.StartTime)},
EndTimestamp: &transit.Timestamp{Time: time.UnixMilli(run.EndTime)},
}
service1, err := connectors.BuildServiceForMetric(hostName, metricBuilder)
if err != nil {
log.Error().Err(err).Str("job_name", run.RunName).Msg("failed to build service for metric")
continue
}
service1.Name = run.RunName

service2, err := connectors.BuildServiceForMetric(hostName, connectors.MetricBuilder{
Name: "latency_seconds",
CustomName: "latency_seconds",
Value: 0,
Graphed: true,
StartTimestamp: &transit.Timestamp{Time: time.UnixMilli(run.StartTime)},
EndTimestamp: &transit.Timestamp{Time: time.UnixMilli(run.EndTime)},
})
if err != nil {
log.Error().Err(err).Str("job_name", run.RunName).Msg("failed to build service for metric")
continue
}
service2.Name = run.RunName

services = append(services, *service0, *service1, *service2)
} else {
currentActiveJobsRuns[run.JobID] = run.RunID
}
}
service, err := connectors.BuildServiceForMultiMetric(hostName, runs[0].RunName, runs[0].RunName, metricBuilders)
if err != nil {
log.Error().Err(err).Str("job_name", runs[0].RunName).Msg("failed to build service for multi metric")
continue
}
services = append(services, *service)
}
}

Expand Down

0 comments on commit a052643

Please sign in to comment.