-
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.
It has limited support of metric types (count, gauge, trend(?)). Only gRPC receiver. Limited configuration.
- Loading branch information
1 parent
9fb92af
commit a477b15
Showing
8 changed files
with
359 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import http from "k6/http"; | ||
import { check } from "k6"; | ||
|
||
export const options = { | ||
vus: 10, | ||
duration: '3m', | ||
thresholds: { | ||
'http_reqs{expected_response:true}': ['rate>10'], | ||
}, | ||
}; | ||
|
||
export default function () { | ||
check(http.get("https://test-api.k6.io/"), { | ||
"status is 200": (r) => r.status == 200, | ||
"protocol is HTTP/2": (r) => r.proto == "HTTP/2.0", | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,36 +1,86 @@ | ||
package opentelemetry | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"time" | ||
|
||
"go.k6.io/k6/output" | ||
) | ||
|
||
const ( | ||
grpcReceiverType = "grpc" | ||
) | ||
|
||
// Config is the config for the template collector | ||
type Config struct { | ||
Address string | ||
// MetricPrefix is the prefix to use for the metrics | ||
MetricPrefix string | ||
// ReceiverType is the type of the receiver to use | ||
ReceiverType string | ||
// GRPCReceiverEndpoint is the endpoint of the gRPC receiver | ||
GRPCReceiverEndpoint string | ||
// PushInterval is the interval at which to push metrics to the receiver | ||
PushInterval time.Duration | ||
// FlushInterval is the interval at which to flush metrics from the k6 | ||
FlushInterval time.Duration | ||
} | ||
|
||
// NewConfig creates a new Config instance from the provided output.Params | ||
// NewConfig creates and validates a new config | ||
func NewConfig(p output.Params) (Config, error) { | ||
cfg := Config{ | ||
Address: "template", | ||
PushInterval: 1 * time.Second, | ||
MetricPrefix: "", | ||
ReceiverType: grpcReceiverType, | ||
GRPCReceiverEndpoint: "localhost:4317", | ||
PushInterval: 1 * time.Second, | ||
FlushInterval: 1 * time.Second, | ||
} | ||
|
||
var err error | ||
for k, v := range p.Environment { | ||
switch k { | ||
case "K6_TEMPLATE_PUSH_INTERVAL": | ||
var err error | ||
case "K6_OTEL_PUSH_INTERVAL": | ||
cfg.PushInterval, err = time.ParseDuration(v) | ||
if err != nil { | ||
return cfg, fmt.Errorf("error parsing environment variable 'K6_TEMPLATE_PUSH_INTERVAL': %w", err) | ||
return cfg, fmt.Errorf("error parsing environment variable 'K6_OTEL_PUSH_INTERVAL': %w", err) | ||
} | ||
case "K6_OTEL_METRIC_PREFIX": | ||
cfg.MetricPrefix = v | ||
case "K6_OTEL_FLUSH_INTERVAL": | ||
cfg.FlushInterval, err = time.ParseDuration(v) | ||
if err != nil { | ||
return cfg, fmt.Errorf("error parsing environment variable 'K6_OTEL_FLUSH_INTERVAL': %w", err) | ||
} | ||
case "K6_TEMPLATE_ADDRESS": | ||
cfg.Address = v | ||
case "K6_OTEL_RECEIVER_TYPE": | ||
cfg.ReceiverType = v | ||
case "K6_OTEL_GRPC_RECEIVER_ENDPOINT": | ||
cfg.GRPCReceiverEndpoint = v | ||
} | ||
} | ||
|
||
// TDOO: consolidated config | ||
|
||
if err = cfg.Validate(); err != nil { | ||
return cfg, fmt.Errorf("error validating config: %w", err) | ||
} | ||
|
||
return cfg, nil | ||
} | ||
|
||
// Validate validates the config | ||
func (c Config) Validate() error { | ||
if c.ReceiverType != grpcReceiverType { | ||
return fmt.Errorf("unsupported receiver type %q, currently only %q supported", c.ReceiverType, grpcReceiverType) | ||
} | ||
|
||
if c.GRPCReceiverEndpoint == "" { | ||
return errors.New("gRPC receiver endpoint is required") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// String returns a string representation of the config | ||
func (c Config) String() string { | ||
return fmt.Sprintf("%s, %s", c.ReceiverType, c.GRPCReceiverEndpoint) | ||
} |
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
Oops, something went wrong.