-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the receiver name to notification metrics (#3045)
* Add receiver name as a label to notify metrics This commit adds in a second label to the notify family of metrics (e.g. numTotalFailedNotifications) - the receiver name. This allows disambiguating which receiver is failing when one has many receivers with the same integration type Signed-off-by: sinkingpoint <[email protected]> * Gate receiver names behind a feature flag Signed-off-by: sinkingpoint <[email protected]> --------- Signed-off-by: sinkingpoint <[email protected]> Signed-off-by: gotjosh <[email protected]> Co-authored-by: gotjosh <[email protected]>
- Loading branch information
1 parent
6ce841c
commit cfe4411
Showing
6 changed files
with
240 additions
and
49 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
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,78 @@ | ||
// Copyright 2023 Prometheus Team | ||
// 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 featurecontrol | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/go-kit/log" | ||
"github.com/go-kit/log/level" | ||
) | ||
|
||
const ( | ||
fcReceiverNameInMetrics = "receiver-name-in-metrics" | ||
) | ||
|
||
var AllowedFlags = []string{fcReceiverNameInMetrics} | ||
|
||
type Flagger interface { | ||
EnableReceiverNamesInMetrics() bool | ||
} | ||
|
||
type Flags struct { | ||
logger log.Logger | ||
enableReceiverNamesInMetrics bool | ||
} | ||
|
||
func (f *Flags) EnableReceiverNamesInMetrics() bool { | ||
return f.enableReceiverNamesInMetrics | ||
} | ||
|
||
type flagOption func(flags *Flags) | ||
|
||
func enableReceiverNameInMetrics() flagOption { | ||
return func(configs *Flags) { | ||
configs.enableReceiverNamesInMetrics = true | ||
} | ||
} | ||
|
||
func NewFlags(logger log.Logger, features string) (Flagger, error) { | ||
fc := &Flags{logger: logger} | ||
opts := []flagOption{} | ||
|
||
if len(features) == 0 { | ||
return NoopFlags{}, nil | ||
} | ||
|
||
for _, feature := range strings.Split(features, ",") { | ||
switch feature { | ||
case fcReceiverNameInMetrics: | ||
opts = append(opts, enableReceiverNameInMetrics()) | ||
level.Warn(logger).Log("msg", "Experimental receiver name in metrics enabled") | ||
default: | ||
return nil, fmt.Errorf("Unknown option '%s' for --enable-feature", feature) | ||
} | ||
} | ||
|
||
for _, opt := range opts { | ||
opt(fc) | ||
} | ||
|
||
return fc, nil | ||
} | ||
|
||
type NoopFlags struct{} | ||
|
||
func (n NoopFlags) EnableReceiverNamesInMetrics() bool { return false } |
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,58 @@ | ||
// Copyright 2023 Prometheus Team | ||
// 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 featurecontrol | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/go-kit/log" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestFlags(t *testing.T) { | ||
tc := []struct { | ||
name string | ||
featureFlags string | ||
err error | ||
}{ | ||
{ | ||
name: "with only valid feature flags", | ||
featureFlags: fcReceiverNameInMetrics, | ||
}, | ||
{ | ||
name: "with only invalid feature flags", | ||
featureFlags: "somethingsomething", | ||
err: errors.New("Unknown option 'somethingsomething' for --enable-feature"), | ||
}, | ||
{ | ||
name: "with both, valid and invalid feature flags", | ||
featureFlags: strings.Join([]string{fcReceiverNameInMetrics, "somethingbad"}, ","), | ||
err: errors.New("Unknown option 'somethingbad' for --enable-feature"), | ||
}, | ||
} | ||
|
||
for _, tt := range tc { | ||
t.Run(tt.name, func(t *testing.T) { | ||
fc, err := NewFlags(log.NewNopLogger(), tt.featureFlags) | ||
if tt.err != nil { | ||
require.EqualError(t, err, tt.err.Error()) | ||
} else { | ||
require.NoError(t, err) | ||
require.NotNil(t, fc) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.