-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add metrics for http origin latency (#30)
* add metrics Signed-off-by: myajima <myajima@yahoo-corp.jp> Signed-off-by: taniwa <taniwa@lycorp.co.jp> * add metrics config Signed-off-by: myajima <myajima@yahoo-corp.jp> Signed-off-by: taniwa <taniwa@lycorp.co.jp> * fix metrics config Signed-off-by: myajima <myajima@yahoo-corp.jp> Signed-off-by: taniwa <taniwa@lycorp.co.jp> * Summary to Histogram Signed-off-by: myajima <myajima@yahoo-corp.jp> Signed-off-by: taniwa <taniwa@lycorp.co.jp> * fix handler test Signed-off-by: myajima <myajima@yahoo-corp.jp> Signed-off-by: taniwa <taniwa@lycorp.co.jp> * add metrics test Signed-off-by: myajima <myajima@yahoo-corp.jp> Signed-off-by: taniwa <taniwa@lycorp.co.jp> * add metrics test Signed-off-by: myajima <myajima@yahoo-corp.jp> Signed-off-by: taniwa <taniwa@lycorp.co.jp> * add metrics ListenAndServe test Signed-off-by: myajima <myajima@yahoo-corp.jp> Signed-off-by: taniwa <taniwa@lycorp.co.jp> * update .licenserc.yaml Signed-off-by: myajima <myajima@yahoo-corp.jp> Signed-off-by: taniwa <taniwa@lycorp.co.jp> * fix authoz_proxyd_test Signed-off-by: myajima <myajima@yahoo-corp.jp> Signed-off-by: taniwa <taniwa@lycorp.co.jp> * change metrics name Signed-off-by: myajima <myajima@yahoo-corp.jp> Signed-off-by: taniwa <taniwa@lycorp.co.jp> * update Signed-off-by: taniwa <taniwa@lycorp.co.jp> * fix metrics_test Signed-off-by: taniwa <taniwa@lycorp.co.jp> * fix metrics.go Signed-off-by: taniwa <taniwa@lycorp.co.jp> * fix metrics interface, unit test Signed-off-by: taniwa <taniwa@lycorp.co.jp> * Update transport_test Signed-off-by: taniwa <taniwa@lycorp.co.jp> * empty Signed-off-by: myajima <myajima@lycorp.co.jp> * update prometheus Signed-off-by: myajima <myajima@lycorp.co.jp> * prometheus version Signed-off-by: myajima <myajima@lycorp.co.jp> --------- Signed-off-by: myajima <myajima@yahoo-corp.jp> Signed-off-by: taniwa <taniwa@lycorp.co.jp> Signed-off-by: myajima <myajima@lycorp.co.jp> Co-authored-by: taniwa <taniwa@lycorp.co.jp> Co-authored-by: t4niwa <114040262+t4niwa@users.noreply.github.com>
- Loading branch information
1 parent
750505e
commit ea12753
Showing
16 changed files
with
803 additions
and
9 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
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
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,60 @@ | ||
// Copyright 2023 LY Corporation | ||
// | ||
// 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 service | ||
|
||
import ( | ||
"github.com/kpango/glg" | ||
"github.com/pkg/errors" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
const ( | ||
HTTP_ORIGIN_LATENCY = "http_origin_latency_in_seconds" | ||
) | ||
|
||
type Metrics interface { | ||
Observe(string, float64) error | ||
} | ||
|
||
type metrics struct { | ||
httpOriginLatency prometheus.Histogram | ||
} | ||
|
||
func NewMetrics() (Metrics, error) { | ||
m := &metrics{ | ||
httpOriginLatency: prometheus.NewHistogram(prometheus.HistogramOpts{ | ||
Name: HTTP_ORIGIN_LATENCY, | ||
Help: "Origin latency in seconds", | ||
Buckets: prometheus.DefBuckets, | ||
}), | ||
} | ||
|
||
err := prometheus.Register(m.httpOriginLatency) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "cannot register metrics") | ||
} | ||
|
||
return m, nil | ||
} | ||
|
||
func (m *metrics) Observe(name string, value float64) error { | ||
switch name { | ||
case HTTP_ORIGIN_LATENCY: | ||
m.httpOriginLatency.Observe(value) | ||
default: | ||
return glg.Errorf("unknown metric name: %s", name) | ||
} | ||
return nil | ||
} |
Oops, something went wrong.