-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exporter type and endpoint config
- Loading branch information
Showing
7 changed files
with
230 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
package controller | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
grpc_client "github.com/cluttrdev/gitlab-exporter/grpc/client" | ||
"github.com/cluttrdev/gitlab-exporter/pkg/models" | ||
) | ||
|
||
type Exporter struct { | ||
clients []*grpc_client.Client | ||
} | ||
|
||
func NewExporter(endpoints []grpc_client.EndpointConfig) (*Exporter, error) { | ||
var clients []*grpc_client.Client | ||
for _, cfg := range endpoints { | ||
c, err := grpc_client.NewCLient(cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
clients = append(clients, c) | ||
} | ||
|
||
return &Exporter{ | ||
clients: clients, | ||
}, nil | ||
} | ||
|
||
func (e *Exporter) RecordPipelines(ctx context.Context, data []*models.Pipeline) error { | ||
var errs error | ||
for _, client := range e.clients { | ||
if err := client.RecordPipelines(ctx, data); err != nil { | ||
errs = errors.Join(errs, err) | ||
} | ||
} | ||
return errs | ||
} | ||
|
||
func (e *Exporter) RecordJobs(ctx context.Context, data []*models.Job) error { | ||
var errs error | ||
for _, client := range e.clients { | ||
if err := client.RecordJobs(ctx, data); err != nil { | ||
errs = errors.Join(errs, err) | ||
} | ||
} | ||
return errs | ||
} | ||
|
||
func (e *Exporter) RecordSections(ctx context.Context, data []*models.Section) error { | ||
var errs error | ||
for _, client := range e.clients { | ||
if err := client.RecordSections(ctx, data); err != nil { | ||
errs = errors.Join(errs, err) | ||
} | ||
} | ||
return errs | ||
} | ||
|
||
func (e *Exporter) RecordBridges(ctx context.Context, data []*models.Bridge) error { | ||
var errs error | ||
for _, client := range e.clients { | ||
if err := client.RecordBridges(ctx, data); err != nil { | ||
errs = errors.Join(errs, err) | ||
} | ||
} | ||
return errs | ||
} | ||
|
||
func (e *Exporter) RecordTestReports(ctx context.Context, reports []*models.PipelineTestReport) error { | ||
var errs error | ||
for _, client := range e.clients { | ||
if err := client.RecordTestReports(ctx, reports); err != nil { | ||
errs = errors.Join(errs, err) | ||
} | ||
} | ||
return errs | ||
} | ||
|
||
func (e *Exporter) RecordTestSuites(ctx context.Context, suites []*models.PipelineTestSuite) error { | ||
var errs error | ||
for _, client := range e.clients { | ||
if err := client.RecordTestSuites(ctx, suites); err != nil { | ||
errs = errors.Join(errs, err) | ||
} | ||
} | ||
return errs | ||
} | ||
|
||
func (e *Exporter) RecordTestCases(ctx context.Context, cases []*models.PipelineTestCase) error { | ||
var errs error | ||
for _, client := range e.clients { | ||
if err := client.RecordTestCases(ctx, cases); err != nil { | ||
errs = errors.Join(errs, err) | ||
} | ||
} | ||
return errs | ||
} | ||
|
||
func (e *Exporter) RecordTraces(ctx context.Context, traces []*models.Trace) error { | ||
var errs error | ||
for _, client := range e.clients { | ||
if err := client.RecordTraces(ctx, traces); err != nil { | ||
errs = errors.Join(errs, err) | ||
} | ||
} | ||
return errs | ||
} | ||
|
||
func (e *Exporter) RecordPipelineHierarchy(ctx context.Context, ph *models.PipelineHierarchy) error { | ||
data, err := flattenPipelineHierarchy(ph) | ||
if err != nil { | ||
return err | ||
} | ||
var errs error | ||
for _, client := range e.clients { | ||
if err := client.RecordPipelines(ctx, data.Pipelines); err != nil { | ||
errs = errors.Join(errs, err) | ||
continue | ||
} | ||
if err := client.RecordJobs(ctx, data.Jobs); err != nil { | ||
errs = errors.Join(errs, err) | ||
continue | ||
} | ||
if err := client.RecordSections(ctx, data.Sections); err != nil { | ||
errs = errors.Join(errs, err) | ||
continue | ||
} | ||
if err := client.RecordBridges(ctx, data.Bridges); err != nil { | ||
errs = errors.Join(errs, err) | ||
continue | ||
} | ||
} | ||
|
||
return errs | ||
} | ||
|
||
type pipelineData struct { | ||
Pipelines []*models.Pipeline | ||
Jobs []*models.Job | ||
Sections []*models.Section | ||
Bridges []*models.Bridge | ||
} | ||
|
||
func flattenPipelineHierarchy(ph *models.PipelineHierarchy) (pipelineData, error) { | ||
var data pipelineData | ||
|
||
data.Pipelines = append(data.Pipelines, ph.Pipeline) | ||
data.Jobs = append(data.Jobs, ph.Jobs...) | ||
data.Sections = append(data.Sections, ph.Sections...) | ||
data.Bridges = append(data.Bridges, ph.Bridges...) | ||
|
||
for _, dph := range ph.DownstreamPipelines { | ||
d, err := flattenPipelineHierarchy(dph) | ||
if err != nil { | ||
return data, err | ||
} | ||
|
||
data.Pipelines = append(data.Pipelines, d.Pipelines...) | ||
data.Jobs = append(data.Jobs, d.Jobs...) | ||
data.Sections = append(data.Sections, d.Sections...) | ||
data.Bridges = append(data.Bridges, d.Bridges...) | ||
} | ||
|
||
return data, nil | ||
} |
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