From 1cd410da9567410f41eb663babe26d61d1568132 Mon Sep 17 00:00:00 2001 From: Antoon Prins Date: Tue, 14 Jul 2020 08:53:59 +0200 Subject: [PATCH 01/16] Configuration for metrics. --- pkg/metrics/config/config.go | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 pkg/metrics/config/config.go diff --git a/pkg/metrics/config/config.go b/pkg/metrics/config/config.go new file mode 100644 index 0000000000..195037973a --- /dev/null +++ b/pkg/metrics/config/config.go @@ -0,0 +1,37 @@ +// 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 config + +// Config holds the config options that need to be passed down to the metrics reader +type Config struct { + Prefix string `mapstructure:"prefix"` + MetricsDataDriverType string `mapstructure:"metrics_data_driver_type"` + MetricsDataLocation string `mapstructure:"metrics_data_location"` +} + +// Init sets sane defaults +func (c *Config) Init() { + if c.Prefix == "" { + c.Prefix = "metrics" + } + if c.MetricsDataDriverType == "json" { + // default values + c.MetricsDataLocation = "/var/tmp/reva/metrics/metricsdata.json" + } +} From ad615cce50fa422436f63a732830e48ebb48c9b7 Mon Sep 17 00:00:00 2001 From: Antoon Prins Date: Tue, 14 Jul 2020 08:55:00 +0200 Subject: [PATCH 02/16] Dummy (test) driver implementation. --- pkg/metrics/reader/driver/dummy/dummy.go | 53 ++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 pkg/metrics/reader/driver/dummy/dummy.go diff --git a/pkg/metrics/reader/driver/dummy/dummy.go b/pkg/metrics/reader/driver/dummy/dummy.go new file mode 100644 index 0000000000..15d90a2ed7 --- /dev/null +++ b/pkg/metrics/reader/driver/dummy/dummy.go @@ -0,0 +1,53 @@ +// 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 dummy + +import ( + "math/rand" + "reva/pkg/metrics/config" +) + +// New returns a new DummyDriver object. +func New(config *config.Config) (*DummyDriver, error) { + driver := &DummyDriver{ + config: config, + } + + return driver, nil +} + +// DummyDriver the DummyDriver struct +type DummyDriver struct { + config *config.Config +} + +// GetNumUsers returns the number of site users, it's a dummy number +func (d *DummyDriver) GetNumUsers() int64 { + return int64(rand.Intn(30000)) +} + +// GetNumGroups returns the number of site groups, it's a dummy number +func (d *DummyDriver) GetNumGroups() int64 { + return int64(rand.Intn(200)) +} + +// GetAmountStorage returns the amount of site storage used, it's a dummy amount +func (d *DummyDriver) GetAmountStorage() int64 { + return int64(rand.Intn(70000000000)) +} From 59c40954ad91fe82da35e20b711fbb7c31cb598d Mon Sep 17 00:00:00 2001 From: Antoon Prins Date: Tue, 14 Jul 2020 08:55:37 +0200 Subject: [PATCH 03/16] JSON metrics data file driver implementation. --- pkg/metrics/reader/driver/json/json.go | 91 ++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 pkg/metrics/reader/driver/json/json.go diff --git a/pkg/metrics/reader/driver/json/json.go b/pkg/metrics/reader/driver/json/json.go new file mode 100644 index 0000000000..e9481e9877 --- /dev/null +++ b/pkg/metrics/reader/driver/json/json.go @@ -0,0 +1,91 @@ +// 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 json + +import ( + "encoding/json" + "errors" + "io/ioutil" + "reva/pkg/metrics/config" +) + +// New returns a new MetricsJSONDriver object. +// It reads the data file from the specified config.MetricsDataLocation upon initializing. +// It does not reload the data file for each metric. +func New(config *config.Config) (*MetricsJSONDriver, error) { + // the json driver reads the data metrics file upon initializing + metricsData, err := readJSON(config) + if err != nil { + return nil, err + } + + driver := &MetricsJSONDriver{ + config: config, + data: metricsData, + } + + return driver, nil +} + +func readJSON(config *config.Config) (*data, error) { + if config.MetricsDataLocation == "" { + err := errors.New("Unable to initialize a metrics data driver, has the data location (metrics_data_location) been configured?") + return nil, err + } + + file, err := ioutil.ReadFile(config.MetricsDataLocation) + if err != nil { + return nil, err + } + + data := &data{} + err = json.Unmarshal(file, data) + if err != nil { + return nil, err + } + + return data, nil +} + +type data struct { + NumUsers int64 `json:"cs3_org_sciencemesh_site_total_num_users"` + NumGroups int64 `json:"cs3_org_sciencemesh_site_total_num_groups"` + AmountStorage int64 `json:"cs3_org_sciencemesh_site_total_amount_storage"` +} + +// MetricsJSONDriver the JsonDriver struct that also holds the data +type MetricsJSONDriver struct { + config *config.Config + data *data +} + +// GetNumUsers returns the number of site users +func (d *MetricsJSONDriver) GetNumUsers() int64 { + return int64(d.data.NumUsers) +} + +// GetNumGroups returns the number of site groups +func (d *MetricsJSONDriver) GetNumGroups() int64 { + return int64(d.data.NumGroups) +} + +// GetAmountStorage returns the amount of site storage used +func (d *MetricsJSONDriver) GetAmountStorage() int64 { + return int64(d.data.AmountStorage) +} From fe4057eff6a30aa40b5c0d259e89e4b47e1c3e93 Mon Sep 17 00:00:00 2001 From: Antoon Prins Date: Tue, 14 Jul 2020 08:57:56 +0200 Subject: [PATCH 04/16] Use new config. Use metrics handler thet wraps prometheus handler. --- .../http/services/prometheus/prometheus.go | 49 ++++++++++++++----- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/internal/http/services/prometheus/prometheus.go b/internal/http/services/prometheus/prometheus.go index d1392dc499..3bb53b8ff0 100644 --- a/internal/http/services/prometheus/prometheus.go +++ b/internal/http/services/prometheus/prometheus.go @@ -20,6 +20,9 @@ package prometheus import ( "net/http" + "reva/pkg/appctx" + "reva/pkg/metrics" + "reva/pkg/metrics/config" "contrib.go.opencensus.io/exporter/prometheus" "github.com/cs3org/reva/pkg/rhttp/global" @@ -27,9 +30,6 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" "go.opencensus.io/stats/view" - - // Initializes goroutines which periodically update stats - _ "github.com/cs3org/reva/pkg/metrics/reader/dummy" ) func init() { @@ -38,32 +38,57 @@ func init() { // New returns a new prometheus service func New(m map[string]interface{}, log *zerolog.Logger) (global.Service, error) { - conf := &config{} + conf := &config.Config{} if err := mapstructure.Decode(m, conf); err != nil { return nil, err } - conf.init() + conf.Init() + + metrics, err := metrics.New(conf) + if err != nil { + return nil, errors.Wrap(err, "prometheus: error creating metrics") + } + // prometheus handler pe, err := prometheus.NewExporter(prometheus.Options{ Namespace: "revad", }) if err != nil { return nil, errors.Wrap(err, "prometheus: error creating exporter") } + // metricsHandler wraps the prometheus handler + metricsHandler := &MetricsHandler{ + pe: pe, + metrics: metrics, + } + view.RegisterExporter(metricsHandler) - view.RegisterExporter(pe) - return &svc{prefix: conf.Prefix, h: pe}, nil + return &svc{prefix: conf.Prefix, h: metricsHandler}, nil } -type config struct { - Prefix string `mapstructure:"prefix"` +// MetricsHandler struct and methods (ServeHTTP, ExportView) is a wrapper for prometheus Exporter +// so we can override (execute our own logic) before forwarding to the prometheus Exporter: see overriding method MetricsHandler.ServeHTTP() +type MetricsHandler struct { + pe *prometheus.Exporter + metrics *metrics.Metrics } -func (c *config) init() { - if c.Prefix == "" { - c.Prefix = "metrics" +// ServeHTTP override and forward to prometheus.Exporter ServeHTTP() +func (h *MetricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + log := appctx.GetLogger(r.Context()) + // make sure the latest metrics data are recorded + if err := h.metrics.RecordMetrics(); err != nil { + log.Err(err).Msg("Unable to record metrics") } + // proceed with regular flow + h.pe.ServeHTTP(w, r) +} + +// ExportView must only be implemented to adhere to prometheus.Exporter signature; we simply forward to prometheus ExportView +func (h *MetricsHandler) ExportView(vd *view.Data) { + // just proceed with regular flow + h.pe.ExportView(vd) } type svc struct { From b14f06ea5f5fe39793a926b151154e879bb662cb Mon Sep 17 00:00:00 2001 From: Antoon Prins Date: Tue, 14 Jul 2020 08:59:21 +0200 Subject: [PATCH 05/16] Metrics now uses data driver to access the actual metrics data. --- pkg/metrics/metrics.go | 157 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 153 insertions(+), 4 deletions(-) diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index 6aa00e15f2..fcece55146 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -19,21 +19,170 @@ package metrics import ( + "context" + "errors" + "reva/pkg/metrics/config" + "reva/pkg/metrics/reader/driver/dummy" + "reva/pkg/metrics/reader/driver/json" + + "github.com/rs/zerolog/log" + "go.opencensus.io/stats" "go.opencensus.io/stats/view" ) -// Reader is the interface that defines how the metrics will be read. +// New returns a Metrics object +func New(c *config.Config) (*Metrics, error) { + m := &Metrics{ + dataDriverType: "", + dataLocation: "", + dataDriver: nil, + config: c, + NumUsersMeasure: stats.Int64("cs3_org_sciencemesh_site_total_num_users", "The total number of users within this site", stats.UnitDimensionless), + NumGroupsMeasure: stats.Int64("cs3_org_sciencemesh_site_total_num_groups", "The total number of groups within this site", stats.UnitDimensionless), + AmountStorageMeasure: stats.Int64("cs3_org_sciencemesh_site_total_amount_storage", "The total amount of storage used within this site", stats.UnitBytes), + } + + // register the desired measures' views + if err := view.Register( + m.getNumUsersView(), + m.getNumGroupsView(), + m.getAmountStorageView(), + ); err != nil { + log.Error().Err(err).Msg("error registering the driver's views with opencensus exporter") + return nil, err + } + + return m, nil +} + +// Metrics the metrics struct +type Metrics struct { + dataDriverType string + dataLocation string + dataDriver Reader // the metrics data driver is an implemention of Reader + config *config.Config + NumUsersMeasure *stats.Int64Measure + NumGroupsMeasure *stats.Int64Measure + AmountStorageMeasure *stats.Int64Measure +} + +// RecordMetrics records the latest metrics from the metrics data source as OpenCensus stats views. +func (m *Metrics) RecordMetrics() error { + if err := initDataDriver(m); err != nil { + log.Error().Err(err).Msg("Could not set a driver") + return err + } + // record all latest metrics + m.recordNumUsers() + m.recordNumGroups() + m.recordAmountStorage() + + return nil +} + +// initDataDriver initializes a data driver and sets it to be the Metrics.dataDriver +func initDataDriver(m *Metrics) error { + // find out what driver to use + if m.config.MetricsDataDriverType == "" { + err := errors.New("Unable to initialize a metrics data driver, has a driver type (metrics_data_driver_type) been configured?") + return err + } + m.dataLocation = m.config.MetricsDataLocation + + // create/init a driver depending on driver type + if m.config.MetricsDataDriverType == "json" { + // Because the json metrics data file is only read on json driver creation + // a json driver must be re-created to make sure we have the current/latest metrics data. + // Other drivers may need creation only once. + jsonDriver, err := json.New(m.config) + if err != nil { + log.Error().Err(err) + return err + } + m.dataDriver = jsonDriver + log.Debug().Msgf("Metrics uses json driver") + } + if m.config.MetricsDataDriverType == "dummy" && m.dataDriver == nil { + // the dummy driver does not need to be initialized every time + dummyDriver, err := dummy.New(m.config) + if err != nil { + log.Error().Err(err) + return err + } + m.dataDriver = dummyDriver + log.Debug().Msgf("Metrics uses dummy driver") + } + // no known driver configured, return error + if m.dataDriver == nil { + err := errors.New("Unable to initialize a metrics data driver. Has a correct driver type (one of: json, dummy) been configured?") + return err + } + + return nil +} + +// recordNumUsers records the latest number of site users figure +func (m *Metrics) recordNumUsers() { + ctx := context.Background() + stats.Record(ctx, m.NumUsersMeasure.M(m.dataDriver.GetNumUsers())) +} + +func (m *Metrics) getNumUsersView() *view.View { + return &view.View{ + Name: m.NumUsersMeasure.Name(), + Description: m.NumUsersMeasure.Description(), + Measure: m.NumUsersMeasure, + Aggregation: view.LastValue(), + } +} + +// recordNumGroups records the latest number of site groups figure +func (m *Metrics) recordNumGroups() { + ctx := context.Background() + stats.Record(ctx, m.NumGroupsMeasure.M(m.dataDriver.GetNumGroups())) +} + +func (m *Metrics) getNumGroupsView() *view.View { + return &view.View{ + Name: m.NumGroupsMeasure.Name(), + Description: m.NumGroupsMeasure.Description(), + Measure: m.NumGroupsMeasure, + Aggregation: view.LastValue(), + } +} + +// recordAmountStorage records the latest amount storage figure +func (m *Metrics) recordAmountStorage() { + ctx := context.Background() + stats.Record(ctx, m.AmountStorageMeasure.M(m.dataDriver.GetAmountStorage())) +} + +func (m *Metrics) getAmountStorageView() *view.View { + return &view.View{ + Name: m.AmountStorageMeasure.Name(), + Description: m.AmountStorageMeasure.Description(), + Measure: m.AmountStorageMeasure, + Aggregation: view.LastValue(), + } +} + +// Reader is the interface that defines the metrics to read. +// Any metrics data driver must implement this interface. +// Each function should return the current/latest available metrics figure relevant to that function. type Reader interface { // GetNumUsersView returns an OpenCensus stats view which records the // number of users registered in the mesh provider. - GetNumUsersView() *view.View + // Metric name: cs3_org_sciencemesh_site_total_num_users + GetNumUsers() int64 // GetNumGroupsView returns an OpenCensus stats view which records the // number of user groups registered in the mesh provider. - GetNumGroupsView() *view.View + // Metric name: cs3_org_sciencemesh_site_total_num_groups + GetNumGroups() int64 // GetAmountStorageView returns an OpenCensus stats view which records the // amount of storage in the system. - GetAmountStorageView() *view.View + // Metric name: cs3_org_sciencemesh_site_total_amount_storage + GetAmountStorage() int64 } From ecb4a0082caad7ce16580c19c59729328a67fe44 Mon Sep 17 00:00:00 2001 From: Antoon Prins Date: Tue, 14 Jul 2020 10:31:53 +0200 Subject: [PATCH 06/16] deleted --- pkg/metrics/reader/dummy/dummy.go | 131 ---------------------------- pkg/metrics/reader/script/script.go | 78 ----------------- 2 files changed, 209 deletions(-) delete mode 100644 pkg/metrics/reader/dummy/dummy.go delete mode 100644 pkg/metrics/reader/script/script.go diff --git a/pkg/metrics/reader/dummy/dummy.go b/pkg/metrics/reader/dummy/dummy.go deleted file mode 100644 index d12947c0fc..0000000000 --- a/pkg/metrics/reader/dummy/dummy.go +++ /dev/null @@ -1,131 +0,0 @@ -// 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 dummy - -import ( - "context" - "math/rand" - "os" - "time" - - "github.com/cs3org/reva/pkg/logger" - "github.com/cs3org/reva/pkg/metrics" - "go.opencensus.io/stats" - "go.opencensus.io/stats/view" -) - -func init() { - - log := logger.New().With().Int("pid", os.Getpid()).Logger() - - m := &Metrics{ - NumUsersMeasure: stats.Int64("cs3_org_sciencemesh_site_total_num_users", "The total number of users within this site", stats.UnitDimensionless), - NumGroupsMeasure: stats.Int64("cs3_org_sciencemesh_site_total_num_groups", "The total number of groups within this site", stats.UnitDimensionless), - AmountStorageMeasure: stats.Int64("cs3_org_sciencemesh_site_total_amount_storage", "The total amount of storage used within this site", stats.UnitBytes), - } - - // Verify that the struct implements the metrics.Reader interface - _, ok := interface{}(m).(metrics.Reader) - if !ok { - log.Error().Msg("the driver does not implement the metrics.Reader interface") - return - } - - // register the desired measures' views - if err := view.Register( - m.GetNumUsersView(), - m.GetNumGroupsView(), - m.GetAmountStorageView(), - ); err != nil { - log.Error().Err(err).Msg("error registering views with opencensus exporter") - return - } - - // call the actual metric provider functions for the latest metrics every 4th second - go func() { - rand.Seed(time.Now().UnixNano()) - for { - m.getNumUsers() - m.getNumGroups() - m.getAmountStorage() - time.Sleep(4 * time.Second) - } - }() -} - -// Metrics returns randomly generated values for the defined metrics. -type Metrics struct { - numUsersCounter int64 - amountStorageCounter int64 - - NumUsersMeasure *stats.Int64Measure - NumGroupsMeasure *stats.Int64Measure - AmountStorageMeasure *stats.Int64Measure -} - -// getNumberUsers links to the underlying number of site users provider -func (m *Metrics) getNumUsers() { - ctx := context.Background() - m.numUsersCounter += int64(rand.Intn(100)) - stats.Record(ctx, m.NumUsersMeasure.M(m.numUsersCounter)) -} - -// GetNumUsersView returns the number of site users measure view -func (m *Metrics) GetNumUsersView() *view.View { - return &view.View{ - Name: m.NumUsersMeasure.Name(), - Description: m.NumUsersMeasure.Description(), - Measure: m.NumUsersMeasure, - Aggregation: view.LastValue(), - } -} - -// getNumberGroups links to the underlying number of site groups provider -func (m *Metrics) getNumGroups() { - ctx := context.Background() - var numGroupsCounter = int64(rand.Intn(100)) - stats.Record(ctx, m.NumGroupsMeasure.M(numGroupsCounter)) -} - -// GetNumGroupsView returns the number of site groups measure view -func (m *Metrics) GetNumGroupsView() *view.View { - return &view.View{ - Name: m.NumGroupsMeasure.Name(), - Description: m.NumGroupsMeasure.Description(), - Measure: m.NumGroupsMeasure, - Aggregation: view.LastValue(), - } -} - -// getAmountStorage links to the underlying amount of storage provider -func (m *Metrics) getAmountStorage() { - ctx := context.Background() - m.amountStorageCounter += int64(rand.Intn(12865000)) - stats.Record(ctx, m.AmountStorageMeasure.M(m.amountStorageCounter)) -} - -// GetAmountStorageView returns the amount of site storage measure view -func (m *Metrics) GetAmountStorageView() *view.View { - return &view.View{ - Name: m.AmountStorageMeasure.Name(), - Description: m.AmountStorageMeasure.Description(), - Measure: m.AmountStorageMeasure, - Aggregation: view.LastValue(), - } -} diff --git a/pkg/metrics/reader/script/script.go b/pkg/metrics/reader/script/script.go deleted file mode 100644 index 79617d5c00..0000000000 --- a/pkg/metrics/reader/script/script.go +++ /dev/null @@ -1,78 +0,0 @@ -// 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 script - -import ( - "os" - - "github.com/cs3org/reva/pkg/logger" - "github.com/cs3org/reva/pkg/metrics" - "go.opencensus.io/stats" - "go.opencensus.io/stats/view" -) - -func init() { - - log := logger.New().With().Int("pid", os.Getpid()).Logger() - - m := &Metrics{ - NumUsersMeasure: stats.Int64("cs3_org_sciencemesh_site_total_num_users", "The total number of users within this site", stats.UnitDimensionless), - NumGroupsMeasure: stats.Int64("cs3_org_sciencemesh_site_total_num_groups", "The total number of groups within this site", stats.UnitDimensionless), - AmountStorageMeasure: stats.Int64("cs3_org_sciencemesh_site_total_amount_storage", "The total amount of storage used within this site", stats.UnitBytes), - } - - // Verify that the struct implements the metrics.Reader interface - _, ok := interface{}(m).(metrics.Reader) - if !ok { - log.Error().Msg("the driver does not implement the metrics.Reader interface") - return - } - - // register the desired measures' views - if err := view.Register( - m.GetNumUsersView(), - m.GetNumGroupsView(), - m.GetAmountStorageView(), - ); err != nil { - log.Error().Err(err).Msg("error registering views with opencensus exporter") - return - } -} - -// Metrics returns randomly generated values for the defined metrics. -type Metrics struct { - NumUsersMeasure *stats.Int64Measure - NumGroupsMeasure *stats.Int64Measure - AmountStorageMeasure *stats.Int64Measure -} - -// GetNumUsersView returns the number of site users measure view -func (m *Metrics) GetNumUsersView() *view.View { - return nil -} - -// GetNumGroupsView returns the number of site groups measure view -func (m *Metrics) GetNumGroupsView() *view.View { - return nil -} - -// GetAmountStorageView returns the amount of site storage measure view -func (m *Metrics) GetAmountStorageView() *view.View { - return nil -} From a79636351d8d99590095e67c647e56d6b6596ffc Mon Sep 17 00:00:00 2001 From: Antoon Prins Date: Tue, 14 Jul 2020 10:34:33 +0200 Subject: [PATCH 07/16] New configuration for metrics. --- examples/metrics/metrics.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/metrics/metrics.toml b/examples/metrics/metrics.toml index caa41975f7..d5203f3b4c 100644 --- a/examples/metrics/metrics.toml +++ b/examples/metrics/metrics.toml @@ -2,6 +2,9 @@ jwt_secret = "Pive-Fumkiu4" [http.services.prometheus] +# metrics_data_driver_type, one of: dummy, json +metrics_data_driver_type = "dummy" +metrics_data_location = "" [http] address = "0.0.0.0:5550" \ No newline at end of file From 676ca4f4e267ba8b29e67de6ec8bf6e7558bca43 Mon Sep 17 00:00:00 2001 From: Antoon Prins Date: Tue, 14 Jul 2020 15:29:31 +0200 Subject: [PATCH 08/16] Changed package name, dummy driver struct name. --- pkg/metrics/metrics.go | 4 +- pkg/metrics/reader/driver/dummy.go | 53 +++++++++++++++++ pkg/metrics/reader/driver/json.go | 91 ++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 pkg/metrics/reader/driver/dummy.go create mode 100644 pkg/metrics/reader/driver/json.go diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index fcece55146..4cddd768f1 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -22,8 +22,8 @@ import ( "context" "errors" "reva/pkg/metrics/config" - "reva/pkg/metrics/reader/driver/dummy" - "reva/pkg/metrics/reader/driver/json" + "reva/pkg/metrics/driver/dummy" + "reva/pkg/metrics/driver/json" "github.com/rs/zerolog/log" "go.opencensus.io/stats" diff --git a/pkg/metrics/reader/driver/dummy.go b/pkg/metrics/reader/driver/dummy.go new file mode 100644 index 0000000000..f454688c47 --- /dev/null +++ b/pkg/metrics/reader/driver/dummy.go @@ -0,0 +1,53 @@ +// 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 driver + +import ( + "math/rand" + "reva/pkg/metrics/config" +) + +// New returns a new DummyDriver object. +func New(config *config.Config) (*DummyDriver, error) { + driver := &DummyDriver{ + config: config, + } + + return driver, nil +} + +// DummyDriver the DummyDriver struct +type DummyDriver struct { + config *config.Config +} + +// GetNumUsers returns the number of site users, it's a dummy number +func (d *DummyDriver) GetNumUsers() int64 { + return int64(rand.Intn(30000)) +} + +// GetNumGroups returns the number of site groups, it's a dummy number +func (d *DummyDriver) GetNumGroups() int64 { + return int64(rand.Intn(200)) +} + +// GetAmountStorage returns the amount of site storage used, it's a dummy amount +func (d *DummyDriver) GetAmountStorage() int64 { + return int64(rand.Intn(70000000000)) +} diff --git a/pkg/metrics/reader/driver/json.go b/pkg/metrics/reader/driver/json.go new file mode 100644 index 0000000000..b0f7a60f0d --- /dev/null +++ b/pkg/metrics/reader/driver/json.go @@ -0,0 +1,91 @@ +// 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 driver + +import ( + "encoding/json" + "errors" + "io/ioutil" + "reva/pkg/metrics/config" +) + +// New returns a new MetricsJSONDriver object. +// It reads the data file from the specified config.MetricsDataLocation upon initializing. +// It does not reload the data file for each metric. +func New(config *config.Config) (*MetricsJSONDriver, error) { + // the json driver reads the data metrics file upon initializing + metricsData, err := readJSON(config) + if err != nil { + return nil, err + } + + driver := &MetricsJSONDriver{ + config: config, + data: metricsData, + } + + return driver, nil +} + +func readJSON(config *config.Config) (*data, error) { + if config.MetricsDataLocation == "" { + err := errors.New("Unable to initialize a metrics data driver, has the data location (metrics_data_location) been configured?") + return nil, err + } + + file, err := ioutil.ReadFile(config.MetricsDataLocation) + if err != nil { + return nil, err + } + + data := &data{} + err = json.Unmarshal(file, data) + if err != nil { + return nil, err + } + + return data, nil +} + +type data struct { + NumUsers int64 `json:"cs3_org_sciencemesh_site_total_num_users"` + NumGroups int64 `json:"cs3_org_sciencemesh_site_total_num_groups"` + AmountStorage int64 `json:"cs3_org_sciencemesh_site_total_amount_storage"` +} + +// MetricsJSONDriver the JsonDriver struct that also holds the data +type MetricsJSONDriver struct { + config *config.Config + data *data +} + +// GetNumUsers returns the number of site users +func (d *MetricsJSONDriver) GetNumUsers() int64 { + return int64(d.data.NumUsers) +} + +// GetNumGroups returns the number of site groups +func (d *MetricsJSONDriver) GetNumGroups() int64 { + return int64(d.data.NumGroups) +} + +// GetAmountStorage returns the amount of site storage used +func (d *MetricsJSONDriver) GetAmountStorage() int64 { + return int64(d.data.AmountStorage) +} From ddf49cd11bb4ef3e7edf7662a191f7ffa381d4c2 Mon Sep 17 00:00:00 2001 From: Antoon Prins Date: Tue, 14 Jul 2020 15:30:31 +0200 Subject: [PATCH 09/16] Changed package name. --- pkg/metrics/reader/driver/dummy/dummy.go | 53 -------------- pkg/metrics/reader/driver/json/json.go | 91 ------------------------ 2 files changed, 144 deletions(-) delete mode 100644 pkg/metrics/reader/driver/dummy/dummy.go delete mode 100644 pkg/metrics/reader/driver/json/json.go diff --git a/pkg/metrics/reader/driver/dummy/dummy.go b/pkg/metrics/reader/driver/dummy/dummy.go deleted file mode 100644 index 15d90a2ed7..0000000000 --- a/pkg/metrics/reader/driver/dummy/dummy.go +++ /dev/null @@ -1,53 +0,0 @@ -// 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 dummy - -import ( - "math/rand" - "reva/pkg/metrics/config" -) - -// New returns a new DummyDriver object. -func New(config *config.Config) (*DummyDriver, error) { - driver := &DummyDriver{ - config: config, - } - - return driver, nil -} - -// DummyDriver the DummyDriver struct -type DummyDriver struct { - config *config.Config -} - -// GetNumUsers returns the number of site users, it's a dummy number -func (d *DummyDriver) GetNumUsers() int64 { - return int64(rand.Intn(30000)) -} - -// GetNumGroups returns the number of site groups, it's a dummy number -func (d *DummyDriver) GetNumGroups() int64 { - return int64(rand.Intn(200)) -} - -// GetAmountStorage returns the amount of site storage used, it's a dummy amount -func (d *DummyDriver) GetAmountStorage() int64 { - return int64(rand.Intn(70000000000)) -} diff --git a/pkg/metrics/reader/driver/json/json.go b/pkg/metrics/reader/driver/json/json.go deleted file mode 100644 index e9481e9877..0000000000 --- a/pkg/metrics/reader/driver/json/json.go +++ /dev/null @@ -1,91 +0,0 @@ -// 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 json - -import ( - "encoding/json" - "errors" - "io/ioutil" - "reva/pkg/metrics/config" -) - -// New returns a new MetricsJSONDriver object. -// It reads the data file from the specified config.MetricsDataLocation upon initializing. -// It does not reload the data file for each metric. -func New(config *config.Config) (*MetricsJSONDriver, error) { - // the json driver reads the data metrics file upon initializing - metricsData, err := readJSON(config) - if err != nil { - return nil, err - } - - driver := &MetricsJSONDriver{ - config: config, - data: metricsData, - } - - return driver, nil -} - -func readJSON(config *config.Config) (*data, error) { - if config.MetricsDataLocation == "" { - err := errors.New("Unable to initialize a metrics data driver, has the data location (metrics_data_location) been configured?") - return nil, err - } - - file, err := ioutil.ReadFile(config.MetricsDataLocation) - if err != nil { - return nil, err - } - - data := &data{} - err = json.Unmarshal(file, data) - if err != nil { - return nil, err - } - - return data, nil -} - -type data struct { - NumUsers int64 `json:"cs3_org_sciencemesh_site_total_num_users"` - NumGroups int64 `json:"cs3_org_sciencemesh_site_total_num_groups"` - AmountStorage int64 `json:"cs3_org_sciencemesh_site_total_amount_storage"` -} - -// MetricsJSONDriver the JsonDriver struct that also holds the data -type MetricsJSONDriver struct { - config *config.Config - data *data -} - -// GetNumUsers returns the number of site users -func (d *MetricsJSONDriver) GetNumUsers() int64 { - return int64(d.data.NumUsers) -} - -// GetNumGroups returns the number of site groups -func (d *MetricsJSONDriver) GetNumGroups() int64 { - return int64(d.data.NumGroups) -} - -// GetAmountStorage returns the amount of site storage used -func (d *MetricsJSONDriver) GetAmountStorage() int64 { - return int64(d.data.AmountStorage) -} From 804fc0f8e89bc52c75ee72659795585430c909d5 Mon Sep 17 00:00:00 2001 From: Antoon Prins Date: Tue, 14 Jul 2020 15:31:19 +0200 Subject: [PATCH 10/16] Changed package name. --- pkg/metrics/driver/dummy/dummy.go | 53 ++++++++++++++++++ pkg/metrics/driver/json/json.go | 91 +++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 pkg/metrics/driver/dummy/dummy.go create mode 100644 pkg/metrics/driver/json/json.go diff --git a/pkg/metrics/driver/dummy/dummy.go b/pkg/metrics/driver/dummy/dummy.go new file mode 100644 index 0000000000..ddd5b2424e --- /dev/null +++ b/pkg/metrics/driver/dummy/dummy.go @@ -0,0 +1,53 @@ +// 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 dummy + +import ( + "math/rand" + "reva/pkg/metrics/config" +) + +// New returns a new DummyDataDriver object. +func New(config *config.Config) (*DummyDataDriver, error) { + driver := &DummyDataDriver{ + config: config, + } + + return driver, nil +} + +// DummyDataDriver the DummyDataDriver struct +type DummyDataDriver struct { + config *config.Config +} + +// GetNumUsers returns the number of site users, it's a dummy number +func (d *DummyDataDriver) GetNumUsers() int64 { + return int64(rand.Intn(30000)) +} + +// GetNumGroups returns the number of site groups, it's a dummy number +func (d *DummyDataDriver) GetNumGroups() int64 { + return int64(rand.Intn(200)) +} + +// GetAmountStorage returns the amount of site storage used, it's a dummy amount +func (d *DummyDataDriver) GetAmountStorage() int64 { + return int64(rand.Intn(70000000000)) +} diff --git a/pkg/metrics/driver/json/json.go b/pkg/metrics/driver/json/json.go new file mode 100644 index 0000000000..e9481e9877 --- /dev/null +++ b/pkg/metrics/driver/json/json.go @@ -0,0 +1,91 @@ +// 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 json + +import ( + "encoding/json" + "errors" + "io/ioutil" + "reva/pkg/metrics/config" +) + +// New returns a new MetricsJSONDriver object. +// It reads the data file from the specified config.MetricsDataLocation upon initializing. +// It does not reload the data file for each metric. +func New(config *config.Config) (*MetricsJSONDriver, error) { + // the json driver reads the data metrics file upon initializing + metricsData, err := readJSON(config) + if err != nil { + return nil, err + } + + driver := &MetricsJSONDriver{ + config: config, + data: metricsData, + } + + return driver, nil +} + +func readJSON(config *config.Config) (*data, error) { + if config.MetricsDataLocation == "" { + err := errors.New("Unable to initialize a metrics data driver, has the data location (metrics_data_location) been configured?") + return nil, err + } + + file, err := ioutil.ReadFile(config.MetricsDataLocation) + if err != nil { + return nil, err + } + + data := &data{} + err = json.Unmarshal(file, data) + if err != nil { + return nil, err + } + + return data, nil +} + +type data struct { + NumUsers int64 `json:"cs3_org_sciencemesh_site_total_num_users"` + NumGroups int64 `json:"cs3_org_sciencemesh_site_total_num_groups"` + AmountStorage int64 `json:"cs3_org_sciencemesh_site_total_amount_storage"` +} + +// MetricsJSONDriver the JsonDriver struct that also holds the data +type MetricsJSONDriver struct { + config *config.Config + data *data +} + +// GetNumUsers returns the number of site users +func (d *MetricsJSONDriver) GetNumUsers() int64 { + return int64(d.data.NumUsers) +} + +// GetNumGroups returns the number of site groups +func (d *MetricsJSONDriver) GetNumGroups() int64 { + return int64(d.data.NumGroups) +} + +// GetAmountStorage returns the amount of site storage used +func (d *MetricsJSONDriver) GetAmountStorage() int64 { + return int64(d.data.AmountStorage) +} From 39f3245ba71496e1f832dc62d6d58b161a8e4b3e Mon Sep 17 00:00:00 2001 From: Antoon Prins Date: Tue, 14 Jul 2020 15:41:51 +0200 Subject: [PATCH 11/16] Struct name changed to please hound bot. --- pkg/metrics/driver/dummy/dummy.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/metrics/driver/dummy/dummy.go b/pkg/metrics/driver/dummy/dummy.go index ddd5b2424e..9e4ec95fe9 100644 --- a/pkg/metrics/driver/dummy/dummy.go +++ b/pkg/metrics/driver/dummy/dummy.go @@ -23,31 +23,31 @@ import ( "reva/pkg/metrics/config" ) -// New returns a new DummyDataDriver object. -func New(config *config.Config) (*DummyDataDriver, error) { - driver := &DummyDataDriver{ +// New returns a new MetricsDummyDriver object. +func New(config *config.Config) (*MetricsDummyDriver, error) { + driver := &MetricsDummyDriver{ config: config, } return driver, nil } -// DummyDataDriver the DummyDataDriver struct -type DummyDataDriver struct { +// MetricsDummyDriver the MetricsDummyDriver struct +type MetricsDummyDriver struct { config *config.Config } // GetNumUsers returns the number of site users, it's a dummy number -func (d *DummyDataDriver) GetNumUsers() int64 { +func (d *MetricsDummyDriver) GetNumUsers() int64 { return int64(rand.Intn(30000)) } // GetNumGroups returns the number of site groups, it's a dummy number -func (d *DummyDataDriver) GetNumGroups() int64 { +func (d *MetricsDummyDriver) GetNumGroups() int64 { return int64(rand.Intn(200)) } // GetAmountStorage returns the amount of site storage used, it's a dummy amount -func (d *DummyDataDriver) GetAmountStorage() int64 { +func (d *MetricsDummyDriver) GetAmountStorage() int64 { return int64(rand.Intn(70000000000)) } From 0280701844828e6ee90d8c3123eb1890326585b6 Mon Sep 17 00:00:00 2001 From: Antoon Prins Date: Tue, 14 Jul 2020 17:58:33 +0200 Subject: [PATCH 12/16] Moved. --- pkg/metrics/reader/driver/dummy.go | 53 ----------------- pkg/metrics/reader/driver/json.go | 91 ------------------------------ 2 files changed, 144 deletions(-) delete mode 100644 pkg/metrics/reader/driver/dummy.go delete mode 100644 pkg/metrics/reader/driver/json.go diff --git a/pkg/metrics/reader/driver/dummy.go b/pkg/metrics/reader/driver/dummy.go deleted file mode 100644 index f454688c47..0000000000 --- a/pkg/metrics/reader/driver/dummy.go +++ /dev/null @@ -1,53 +0,0 @@ -// 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 driver - -import ( - "math/rand" - "reva/pkg/metrics/config" -) - -// New returns a new DummyDriver object. -func New(config *config.Config) (*DummyDriver, error) { - driver := &DummyDriver{ - config: config, - } - - return driver, nil -} - -// DummyDriver the DummyDriver struct -type DummyDriver struct { - config *config.Config -} - -// GetNumUsers returns the number of site users, it's a dummy number -func (d *DummyDriver) GetNumUsers() int64 { - return int64(rand.Intn(30000)) -} - -// GetNumGroups returns the number of site groups, it's a dummy number -func (d *DummyDriver) GetNumGroups() int64 { - return int64(rand.Intn(200)) -} - -// GetAmountStorage returns the amount of site storage used, it's a dummy amount -func (d *DummyDriver) GetAmountStorage() int64 { - return int64(rand.Intn(70000000000)) -} diff --git a/pkg/metrics/reader/driver/json.go b/pkg/metrics/reader/driver/json.go deleted file mode 100644 index b0f7a60f0d..0000000000 --- a/pkg/metrics/reader/driver/json.go +++ /dev/null @@ -1,91 +0,0 @@ -// 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 driver - -import ( - "encoding/json" - "errors" - "io/ioutil" - "reva/pkg/metrics/config" -) - -// New returns a new MetricsJSONDriver object. -// It reads the data file from the specified config.MetricsDataLocation upon initializing. -// It does not reload the data file for each metric. -func New(config *config.Config) (*MetricsJSONDriver, error) { - // the json driver reads the data metrics file upon initializing - metricsData, err := readJSON(config) - if err != nil { - return nil, err - } - - driver := &MetricsJSONDriver{ - config: config, - data: metricsData, - } - - return driver, nil -} - -func readJSON(config *config.Config) (*data, error) { - if config.MetricsDataLocation == "" { - err := errors.New("Unable to initialize a metrics data driver, has the data location (metrics_data_location) been configured?") - return nil, err - } - - file, err := ioutil.ReadFile(config.MetricsDataLocation) - if err != nil { - return nil, err - } - - data := &data{} - err = json.Unmarshal(file, data) - if err != nil { - return nil, err - } - - return data, nil -} - -type data struct { - NumUsers int64 `json:"cs3_org_sciencemesh_site_total_num_users"` - NumGroups int64 `json:"cs3_org_sciencemesh_site_total_num_groups"` - AmountStorage int64 `json:"cs3_org_sciencemesh_site_total_amount_storage"` -} - -// MetricsJSONDriver the JsonDriver struct that also holds the data -type MetricsJSONDriver struct { - config *config.Config - data *data -} - -// GetNumUsers returns the number of site users -func (d *MetricsJSONDriver) GetNumUsers() int64 { - return int64(d.data.NumUsers) -} - -// GetNumGroups returns the number of site groups -func (d *MetricsJSONDriver) GetNumGroups() int64 { - return int64(d.data.NumGroups) -} - -// GetAmountStorage returns the amount of site storage used -func (d *MetricsJSONDriver) GetAmountStorage() int64 { - return int64(d.data.AmountStorage) -} From 87d96c49e58f68fbe646303a6bb29be68e9ff651 Mon Sep 17 00:00:00 2001 From: Antoon Prins Date: Tue, 14 Jul 2020 17:59:19 +0200 Subject: [PATCH 13/16] Imports fixed --- internal/http/services/prometheus/prometheus.go | 7 ++++--- pkg/metrics/driver/dummy/dummy.go | 3 ++- pkg/metrics/driver/json/json.go | 3 ++- pkg/metrics/metrics.go | 7 ++++--- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/internal/http/services/prometheus/prometheus.go b/internal/http/services/prometheus/prometheus.go index 3bb53b8ff0..50536b5e2f 100644 --- a/internal/http/services/prometheus/prometheus.go +++ b/internal/http/services/prometheus/prometheus.go @@ -20,9 +20,10 @@ package prometheus import ( "net/http" - "reva/pkg/appctx" - "reva/pkg/metrics" - "reva/pkg/metrics/config" + + "github.com/cs3org/reva/pkg/appctx" + "github.com/cs3org/reva/pkg/metrics" + "github.com/cs3org/reva/pkg/metrics/config" "contrib.go.opencensus.io/exporter/prometheus" "github.com/cs3org/reva/pkg/rhttp/global" diff --git a/pkg/metrics/driver/dummy/dummy.go b/pkg/metrics/driver/dummy/dummy.go index 9e4ec95fe9..010201610d 100644 --- a/pkg/metrics/driver/dummy/dummy.go +++ b/pkg/metrics/driver/dummy/dummy.go @@ -20,7 +20,8 @@ package dummy import ( "math/rand" - "reva/pkg/metrics/config" + + "github.com/cs3org/reva/pkg/metrics/config" ) // New returns a new MetricsDummyDriver object. diff --git a/pkg/metrics/driver/json/json.go b/pkg/metrics/driver/json/json.go index e9481e9877..a7d79eb670 100644 --- a/pkg/metrics/driver/json/json.go +++ b/pkg/metrics/driver/json/json.go @@ -22,7 +22,8 @@ import ( "encoding/json" "errors" "io/ioutil" - "reva/pkg/metrics/config" + + "github.com/cs3org/reva/pkg/metrics/config" ) // New returns a new MetricsJSONDriver object. diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index 4cddd768f1..af865f38a9 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -21,9 +21,10 @@ package metrics import ( "context" "errors" - "reva/pkg/metrics/config" - "reva/pkg/metrics/driver/dummy" - "reva/pkg/metrics/driver/json" + + "github.com/cs3org/reva/pkg/metrics/config" + "github.com/cs3org/reva/pkg/metrics/driver/dummy" + "github.com/cs3org/reva/pkg/metrics/driver/json" "github.com/rs/zerolog/log" "go.opencensus.io/stats" From 1697d075eeb00277dc9fb7d44d27b19e211ccd86 Mon Sep 17 00:00:00 2001 From: Antoon Prins Date: Tue, 14 Jul 2020 18:21:14 +0200 Subject: [PATCH 14/16] Fixed unnecessary conversion. --- pkg/metrics/driver/json/json.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/metrics/driver/json/json.go b/pkg/metrics/driver/json/json.go index a7d79eb670..29b880dfab 100644 --- a/pkg/metrics/driver/json/json.go +++ b/pkg/metrics/driver/json/json.go @@ -78,15 +78,15 @@ type MetricsJSONDriver struct { // GetNumUsers returns the number of site users func (d *MetricsJSONDriver) GetNumUsers() int64 { - return int64(d.data.NumUsers) + return d.data.NumUsers } // GetNumGroups returns the number of site groups func (d *MetricsJSONDriver) GetNumGroups() int64 { - return int64(d.data.NumGroups) + return d.data.NumGroups } // GetAmountStorage returns the amount of site storage used func (d *MetricsJSONDriver) GetAmountStorage() int64 { - return int64(d.data.AmountStorage) + return d.data.AmountStorage } From 82de7deac5618a9c2019c475f3466a5962d03051 Mon Sep 17 00:00:00 2001 From: Antoon Prins Date: Wed, 15 Jul 2020 09:43:47 +0200 Subject: [PATCH 15/16] Changelog added. --- changelog/unreleased/read-metrics-from-file.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/unreleased/read-metrics-from-file.md diff --git a/changelog/unreleased/read-metrics-from-file.md b/changelog/unreleased/read-metrics-from-file.md new file mode 100644 index 0000000000..d6aabb1c7c --- /dev/null +++ b/changelog/unreleased/read-metrics-from-file.md @@ -0,0 +1,5 @@ +Enhancement: Metrics module can be configured to retrieve metrics data from file. + +- Export site metrics in Prometheus #698 + +https://github.com/cs3org/reva/pull/973 From 6452d0e0151658ca4ff99e325a75b649b04d9ba6 Mon Sep 17 00:00:00 2001 From: Antoon Prins Date: Wed, 15 Jul 2020 16:45:05 +0200 Subject: [PATCH 16/16] Fixed: custom json file location not used. --- pkg/metrics/config/config.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/metrics/config/config.go b/pkg/metrics/config/config.go index 195037973a..0cef040983 100644 --- a/pkg/metrics/config/config.go +++ b/pkg/metrics/config/config.go @@ -32,6 +32,8 @@ func (c *Config) Init() { } if c.MetricsDataDriverType == "json" { // default values - c.MetricsDataLocation = "/var/tmp/reva/metrics/metricsdata.json" + if c.MetricsDataLocation == "" { + c.MetricsDataLocation = "/var/tmp/reva/metrics/metricsdata.json" + } } }