-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[extension/ecsobserver] Add get ip and port from task (#3133)
* ext: ecsobserver Add get ip and port from task * ext: ecsobserver Add merge container and target * ext: ecsobserver Fix MergeTarget logic Based on review comments from Anthony - Add error struct for ip and port error, we can report metrics later. - MergeTarget is wrong, add unit test to make sure it is merging new target only once instead of multiply by existing targets :D - Fix typos
- Loading branch information
Showing
4 changed files
with
491 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package ecsobserver | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMatchedContainer_MergeTargets(t *testing.T) { | ||
t.Run("add new targets", func(t *testing.T) { | ||
m := MatchedContainer{ | ||
Targets: []MatchedTarget{ | ||
{ | ||
Port: 1234, | ||
MetricsPath: "/m1", | ||
}, | ||
{ | ||
Port: 1235, | ||
MetricsPath: "/m2", | ||
}, | ||
}, | ||
} | ||
newTargets := []MatchedTarget{ | ||
{ | ||
Port: 1234, | ||
MetricsPath: "/not-m1", // different path | ||
}, | ||
{ | ||
Port: 1235, // different port | ||
MetricsPath: "/m1", | ||
}, | ||
} | ||
m.MergeTargets(newTargets) | ||
assert.Len(t, m.Targets, 4) | ||
assert.Equal(t, m.Targets[3].MetricsPath, "/m1") // order is append | ||
}) | ||
|
||
t.Run("respect existing targets", func(t *testing.T) { | ||
m := MatchedContainer{ | ||
Targets: []MatchedTarget{ | ||
{ | ||
MatcherType: MatcherTypeService, | ||
Port: 1234, | ||
MetricsPath: "/m1", | ||
}, | ||
{ | ||
Port: 1235, | ||
MetricsPath: "/m2", | ||
}, | ||
}, | ||
} | ||
newTargets := []MatchedTarget{ | ||
{ | ||
MatcherType: MatcherTypeDockerLabel, // different matcher | ||
Port: 1234, | ||
MetricsPath: "/m1", | ||
}, | ||
{ | ||
Port: 1235, // different port | ||
MetricsPath: "/m1", | ||
}, | ||
} | ||
m.MergeTargets(newTargets) | ||
assert.Len(t, m.Targets, 3) | ||
assert.Equal(t, MatcherTypeService, m.Targets[0].MatcherType) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.