-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The system info metrics now use OpenCensus #1114
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d5bed5d
Merge pull request #1 from cs3org/master
Daniel-WWU-IT 82afa69
The system info metrics now use OpenCensus instead of the Prometheus …
Daniel-WWU-IT c80f50a
Lint fixes
Daniel-WWU-IT bb44d96
Moved the system info metrics registration out of the Prometheus service
Daniel-WWU-IT 5c1ab6d
Added changelog
Daniel-WWU-IT 1a1a0f5
Some cleanup
Daniel-WWU-IT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Enhancement: System information metrics now use OpenCensus and were moved out of the Prometheus service | ||
|
||
The system information metrics are now based on OpenCensus instead of the Prometheus client library. Furthermore, its initialization was moved out of the Prometheus HTTP service to keep things clean. | ||
|
||
https://github.com/cs3org/reva/pull/1114 |
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,134 @@ | ||
// Copyright 2018-2020 CERN | ||
// | ||
// 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. | ||
// | ||
// In applying this license, CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
package sysinfo | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"reflect" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
"go.opencensus.io/stats" | ||
"go.opencensus.io/stats/view" | ||
"go.opencensus.io/tag" | ||
|
||
"github.com/cs3org/reva/pkg/utils" | ||
) | ||
|
||
type sysInfoMetricsLabels = map[tag.Key]string | ||
|
||
type sysInfoMetrics struct { | ||
sysInfoStats *stats.Int64Measure | ||
sysInfoView *view.View | ||
|
||
labels sysInfoMetricsLabels | ||
|
||
ctx context.Context | ||
} | ||
|
||
var ( | ||
metrics *sysInfoMetrics | ||
) | ||
|
||
func (m *sysInfoMetrics) init() error { | ||
m.labels = m.getLabels("", SysInfo) | ||
|
||
// Collect all labels and their values; the values are stored as mutators | ||
tagKeys := make([]tag.Key, 0, len(m.labels)) | ||
mutators := make([]tag.Mutator, 0, len(m.labels)) | ||
for key, value := range m.labels { | ||
tagKeys = append(tagKeys, key) | ||
mutators = append(mutators, tag.Insert(key, value)) | ||
} | ||
|
||
// Create the OpenCensus statistics and a corresponding view | ||
m.sysInfoStats = stats.Int64("sys_info", "A metric with a constant '1' value labeled by various system information elements", stats.UnitDimensionless) | ||
m.sysInfoView = &view.View{ | ||
Name: m.sysInfoStats.Name(), | ||
Description: m.sysInfoStats.Description(), | ||
Measure: m.sysInfoStats, | ||
TagKeys: tagKeys, | ||
Aggregation: view.LastValue(), | ||
} | ||
|
||
if err := view.Register(m.sysInfoView); err != nil { | ||
return errors.Wrap(err, "unable to register the system info view") | ||
} | ||
|
||
// Create a new context to serve the metrics | ||
if ctx, err := tag.New(context.Background(), mutators...); err == nil { | ||
m.ctx = ctx | ||
} else { | ||
return errors.Wrap(err, "unable to create a context") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (m *sysInfoMetrics) getLabels(root string, i interface{}) sysInfoMetricsLabels { | ||
labels := sysInfoMetricsLabels{} | ||
|
||
// Iterate over each field of the given interface, recursively collecting the values as labels | ||
v := reflect.ValueOf(i).Elem() | ||
for i := 0; i < v.NumField(); i++ { | ||
// Check if the field was tagged with 'sysinfo:omitlabel'; if so, skip this field | ||
tags := v.Type().Field(i).Tag.Get("sysinfo") | ||
if strings.Contains(tags, "omitlabel") { | ||
continue | ||
} | ||
|
||
// Get the name of the field from the parent structure | ||
fieldName := utils.ToSnakeCase(v.Type().Field(i).Name) | ||
if len(root) > 0 { | ||
fieldName = "_" + fieldName | ||
} | ||
fieldName = root + fieldName | ||
|
||
// Check if the field is either a struct or a pointer to a struct; in that case, process the field recursively | ||
f := v.Field(i) | ||
if f.Kind() == reflect.Struct || (f.Kind() == reflect.Ptr && f.Elem().Kind() == reflect.Struct) { | ||
// Merge labels recursively | ||
for key, val := range m.getLabels(fieldName, f.Interface()) { | ||
labels[key] = val | ||
} | ||
} else { // Store the value of the field in the labels | ||
key := tag.MustNewKey(fieldName) | ||
labels[key] = fmt.Sprintf("%v", f) | ||
} | ||
} | ||
|
||
return labels | ||
} | ||
|
||
func (m *sysInfoMetrics) record() { | ||
// Just record a simple hardcoded '1' to expose the system info as a metric | ||
stats.Record(m.ctx, m.sysInfoStats.M(1)) | ||
} | ||
|
||
func registerSystemInfoMetrics() error { | ||
// Create and initialize the local system info metrics object | ||
metrics = &sysInfoMetrics{} | ||
if err := metrics.init(); err != nil { | ||
return errors.Wrap(err, "unable to initialize the system information metrics") | ||
} | ||
|
||
metrics.record() | ||
return nil | ||
} |
This file was deleted.
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the struct and the global variable? Let's just get the labels and register them.