Skip to content

Commit

Permalink
b/352186158 Ignore order of label attributes (#24)
Browse files Browse the repository at this point in the history
While attributes are usually in the order 'key, value',
they can sometimes be reversed. Fix parsing logic to
not rely on order.
  • Loading branch information
jpassing authored Jul 10, 2024
1 parent 5045002 commit 23c88a3
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public void WhenFirstOperationAndLabelsNotEmpty_ThenLabelsAreSet()
'value': 'value-1'
},
{
'key': 'label-2',
'value': 'value-2'
'value': 'value-2',
'key': 'label-2'
},
{
'key': 'label-2',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public void WhenFirstOperation_ThenMachineTypeIsSet()
},
'labels': [
{
'key': 'label-1',
'value': 'value-1'
'value': 'value-1',
'key': 'label-1'
},
{
'key': 'label-2',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ public void WhenInstanceHasDuplicateLabels_ThenFieldsAreExtracted()
},
'labels': [
{
'key': 'label-1',
'value': 'value-1'
'value': 'value-1',
'key': 'label-1'
},
{
'key': 'label-1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public SetLabelsEvent(LogRecord logRecord) : base(logRecord)
this.Labels = labels
.OfType<JObject>()
.Select(item => new {
Key = (string?)item.PropertyValues().ElementAtOrDefault(0),
Value = (string?)item.PropertyValues().ElementAtOrDefault(1)
Key = (string?)item.Value<string?>("key"),
Value = (string?)item.Value<string?>("value")
})
.Where(item => item.Key != null && item.Value != null)
.DistinctBy(item => item.Key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public UpdateInstanceEvent(LogRecord logRecord) : base(logRecord)
this.Labels = labels
.OfType<JObject>()
.Select(item => new {
Key = (string?)item.PropertyValues().ElementAtOrDefault(0),
Value = (string?)item.PropertyValues().ElementAtOrDefault(1)
Key = (string?)item.Value<string?>("key"),
Value = (string?)item.Value<string?>("value")
})
.Where(item => item.Key != null && item.Value != null)
.DistinctBy(item => item.Key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ internal InsertInstanceEvent(LogRecord logRecord) : base(logRecord)
this.Labels = labels
.OfType<JObject>()
.Select(item => new {
Key = (string?)item.PropertyValues().ElementAtOrDefault(0),
Value = (string?)item.PropertyValues().ElementAtOrDefault(1)
Key = (string?)item.Value<string?>("key"),
Value = (string?)item.Value<string?>("value")
})
.Where(item => item.Key != null && item.Value != null)
.DistinctBy(item => item.Key)
Expand Down

0 comments on commit 23c88a3

Please sign in to comment.