Skip to content

Commit

Permalink
Remove unused function argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivaka committed Mar 22, 2024
1 parent 56f53a1 commit 88f6cdc
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 26 deletions.
2 changes: 1 addition & 1 deletion internal/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (e *exporter) export(ctx context.Context) error {
return nil
}

batch := e.mapper.Map(metricFamilies, time.Now())
batch := e.mapper.Map(metricFamilies)
if err := e.client.UploadBatch(ctx, batch); err != nil {
return fmt.Errorf("error whlie sending %d metrics to castai %w", len(batch.Metrics), err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/exporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestExporter_Running(t *testing.T) {
batch := &pb.MetricsBatch{}

scraper.EXPECT().Scrape(ctx, []string{"http://192.168.1.1:9400/metrics"}).Times(1).Return(metricFamilies, nil)
mapper.EXPECT().Map(metricFamilies, mock.Anything).Times(1).Return(batch, nil)
mapper.EXPECT().Map(metricFamilies).Times(1).Return(batch, nil)
client.EXPECT().UploadBatch(mock.Anything, batch).Times(1).Return(nil, nil)

go func() {
Expand Down
6 changes: 2 additions & 4 deletions internal/exporter/mapper.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package exporter

import (
"time"

"github.com/castai/gpu-metrics-exporter/pb"
)

type MetricMapper interface {
Map(metrics []MetricFamilyMap, ts time.Time) *pb.MetricsBatch
Map(metrics []MetricFamilyMap) *pb.MetricsBatch
}

type metricMapper struct{}
Expand All @@ -16,7 +14,7 @@ func NewMapper() MetricMapper {
return &metricMapper{}
}

func (p metricMapper) Map(metricFamilyMaps []MetricFamilyMap, ts time.Time) *pb.MetricsBatch {
func (p metricMapper) Map(metricFamilyMaps []MetricFamilyMap) *pb.MetricsBatch {
metrics := &pb.MetricsBatch{}
metricsMap := make(map[string]*pb.Metric)
for _, familyMap := range metricFamilyMaps {
Expand Down
10 changes: 3 additions & 7 deletions internal/exporter/mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package exporter_test

import (
"testing"
"time"

dto "github.com/prometheus/client_model/go"
"github.com/stretchr/testify/require"
Expand All @@ -28,18 +27,16 @@ func TestMetricMapper_Map(t *testing.T) {
mapper := exporter.NewMapper()

t.Run("empty input yields empty MetricsBatch", func(t *testing.T) {
ts := time.Now()
metricFamilyMaps := []exporter.MetricFamilyMap{}

got := mapper.Map(metricFamilyMaps, ts)
got := mapper.Map(metricFamilyMaps)
expected := &pb.MetricsBatch{}

r := require.New(t)
r.Equal(expected, got)
})

t.Run("metric familiy which is not enabled is skipped", func(t *testing.T) {
ts := time.Now()
metricFamilyMaps := []exporter.MetricFamilyMap{
{
"test_gauge": {
Expand All @@ -56,15 +53,14 @@ func TestMetricMapper_Map(t *testing.T) {
},
}

got := mapper.Map(metricFamilyMaps, ts)
got := mapper.Map(metricFamilyMaps)
expected := &pb.MetricsBatch{}

r := require.New(t)
r.Equal(expected, got)
})

t.Run("enabled metric family is included", func(t *testing.T) {
ts := time.Now()
metricFamilyMaps := []exporter.MetricFamilyMap{
{
"test_gauge": {
Expand Down Expand Up @@ -92,7 +88,7 @@ func TestMetricMapper_Map(t *testing.T) {
},
}

got := mapper.Map(metricFamilyMaps, ts)
got := mapper.Map(metricFamilyMaps)
expected := &pb.MetricsBatch{
Metrics: []*pb.Metric{
{
Expand Down
23 changes: 10 additions & 13 deletions mock/exporter/mock_MetricMapper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 88f6cdc

Please sign in to comment.