-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
policyfilter: implement ErrorLabel() for metrics
This patch implements ErrorLabel() for generating error labels for metrics. This fixes an issue with the previous implementation where the cardinality of the error_type label was potentially unbounded. Signed-off-by: Kornilios Kourtis <[email protected]>
- Loading branch information
Showing
7 changed files
with
62 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,32 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Tetragon | ||
|
||
package policyfilter | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// podNamespaceConflictErr: even if a pod changes, we expect the namespace to remain the same | ||
type podNamespaceConflictErr struct { | ||
podID PodID | ||
oldNs, newNs string | ||
} | ||
|
||
func (e *podNamespaceConflictErr) Error() string { | ||
return fmt.Sprintf("conflicting namespaces for pod with id '%s': old='%s' vs new='%s'", | ||
e.podID.String(), e.oldNs, e.newNs) | ||
} | ||
|
||
// ErrorLabel returns an error label with a small cardinality so it can be used in metrics | ||
func ErrorLabel(err error) string { | ||
if err == nil { | ||
return "" | ||
} | ||
switch err.(type) { | ||
case *podNamespaceConflictErr: | ||
return "pod-namespace-conflict" | ||
default: | ||
return "generic-error" | ||
} | ||
} |
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,16 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Tetragon | ||
|
||
package policyfilter | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestErrorLabel(t *testing.T) { | ||
var err error = &podNamespaceConflictErr{PodID{}, "foo", "lala"} | ||
require.Equal(t, "", ErrorLabel(nil)) | ||
require.Equal(t, "pod-namespace-conflict", ErrorLabel(err)) | ||
} |
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