Skip to content

Commit

Permalink
Adds metric tags to task logs (#50)
Browse files Browse the repository at this point in the history
Signed-off-by: Rebecca Roberts <[email protected]>
Co-authored-by: Andrew Crump <[email protected]>
  • Loading branch information
rroberts2222 and acrmp authored Dec 20, 2023
1 parent eedf2cd commit c55fff8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
9 changes: 8 additions & 1 deletion conversion_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (rrch RunRequestConversionHelper) NewRunRequestFromDesiredLRP(
return executor.RunRequest{}, err
}

metricTags, err := models.ConvertMetricTags(desiredLRP.MetricTags, map[models.MetricTagValue_DynamicValue]interface{}{
metricTags, err := models.ConvertMetricTags(desiredLRP.MetricTags, map[models.MetricTagValue_DynamicValue]any{
models.MetricTagDynamicValueIndex: lrpKey.Index,
models.MetricTagDynamicValueInstanceGuid: lrpInstanceKey.InstanceGuid,
})
Expand Down Expand Up @@ -276,6 +276,11 @@ func (rrch RunRequestConversionHelper) NewRunRequestFromTask(task *models.Task,
return executor.RunRequest{}, err
}

metricTags, err := models.ConvertMetricTags(task.MetricTags, map[models.MetricTagValue_DynamicValue]any{})
if err != nil {
return executor.RunRequest{}, err
}

username, password, err := rrch.convertCredentials(rootFSPath, task.ImageUsername, task.ImagePassword)
if err != nil {
return executor.RunRequest{}, err
Expand All @@ -291,9 +296,11 @@ func (rrch RunRequestConversionHelper) NewRunRequestFromTask(task *models.Task,
LogConfig: executor.LogConfig{
Guid: task.LogGuid,
SourceName: task.LogSource,
Tags: metricTags,
},
MetricsConfig: executor.MetricsConfig{
Guid: task.MetricsGuid,
Tags: metricTags,
},
CachedDependencies: ConvertCachedDependencies(cachedDependencies),
Action: task.Action,
Expand Down
18 changes: 17 additions & 1 deletion conversion_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ var _ = Describe("Resources", func() {
Expect(runReq.RunInfo.LogConfig.Tags).To(HaveKeyWithValue("tag1", "foo"))
})

It("populates tags with dynamic values according its enum value ", func() {
It("populates tags with dynamic values according to its enum value", func() {
runReq, err := runRequestConversionHelper.NewRunRequestFromDesiredLRP(containerGuid, desiredLRP, &actualLRP.ActualLRPKey, &actualLRP.ActualLRPInstanceKey, stackPathMap, rep.LayeringModeSingleLayer)
Expect(err).NotTo(HaveOccurred())
Expect(runReq.RunInfo.MetricsConfig.Tags).To(HaveKeyWithValue("index", "9"))
Expand Down Expand Up @@ -696,9 +696,15 @@ var _ = Describe("Resources", func() {
LogConfig: executor.LogConfig{
Guid: task.LogGuid,
SourceName: task.LogSource,
Tags: map[string]string{
"source_id": "some-metrics-guid",
},
},
MetricsConfig: executor.MetricsConfig{
Guid: task.MetricsGuid,
Tags: map[string]string{
"source_id": "some-metrics-guid",
},
},
Action: task.Action,
Env: executor.EnvironmentVariablesFromModel(task.EnvironmentVariables),
Expand Down Expand Up @@ -727,6 +733,16 @@ var _ = Describe("Resources", func() {
}))
})

Context("when the task tags contain dynamic fields not applicable to tasks", func() {
BeforeEach(func() {
task.MetricTags["index"] = &models.MetricTagValue{Dynamic: models.MetricTagDynamicValueIndex}
})
It("errors", func() {
_, err := runRequestConversionHelper.NewRunRequestFromTask(task, stackPathMap, rep.LayeringModeSingleLayer)
Expect(err).To(HaveOccurred())
})
})

Context("when the network is nil", func() {
BeforeEach(func() {
task.Network = nil
Expand Down

0 comments on commit c55fff8

Please sign in to comment.