Skip to content

Commit

Permalink
Reuse cloud API address config key for error telemetries APIs (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
amitlicht committed Jul 2, 2024
1 parent ad0a9d8 commit 79fa7a5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/shared/telemetries/errorreporter/errorsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package errorreporter

import (
"context"
"fmt"
"github.com/Khan/genqlient/graphql"
"github.com/otterize/intents-operator/src/shared/errors"
"github.com/otterize/intents-operator/src/shared/otterizecloud/otterizecloudclient"
"github.com/otterize/intents-operator/src/shared/telemetries/basicbatch"
"github.com/otterize/intents-operator/src/shared/telemetries/telemetriesconfig"
"github.com/otterize/intents-operator/src/shared/telemetries/telemetriesgql"
Expand All @@ -21,10 +23,11 @@ type ErrorSender struct {
}

func newGqlClient() graphql.Client {
apiAddress := viper.GetString(telemetriesconfig.TelemetryAPIAddressKey)
apiAddress := viper.GetString(otterizecloudclient.OtterizeAPIAddressKey)
graphqlUrl := fmt.Sprintf("%s/telemetry/query", apiAddress)
clientTimeout := viper.GetDuration(telemetriesconfig.TimeoutKey)
clientWithTimeout := &http.Client{Timeout: clientTimeout}
return graphql.NewClient(apiAddress, clientWithTimeout)
return graphql.NewClient(graphqlUrl, clientWithTimeout)
}

func (s *ErrorSender) SendSync(errs []*telemetriesgql.Error) error {
Expand Down
6 changes: 0 additions & 6 deletions src/shared/telemetries/telemetriesconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
)

const (
TelemetryAPIAddressKey = "telemetry-address"
TelemetryAPIAddressDefault = "https://app.otterize.com/api/telemetry/query"
TimeoutKey = "telemetry-client-timeout"
CloudClientTimeoutDefault = "30s"
TelemetryEnabledKey = "telemetry-enabled"
Expand All @@ -26,13 +24,10 @@ const (
TelemetryErrorEnabledDefault = true
TelemetryErrorsStageKey = "telemetry-errors-stage"
TelemetryErrorsStageDefault = "production"
TelemetryErrorsAddressKey = "telemetry-errors-address"
TelemetryErrorsAddressDefault = "https://app.otterize.com/api/errors"
EnvPrefix = "OTTERIZE"
)

func init() {
viper.SetDefault(TelemetryAPIAddressKey, TelemetryAPIAddressDefault)
viper.SetDefault(TimeoutKey, CloudClientTimeoutDefault)
viper.SetDefault(TelemetryIntervalKey, TelemetryIntervalDefault)
viper.SetDefault(TelemetryMaxBatchSizeKey, TelemetryMaxBatchSizeDefault)
Expand All @@ -42,7 +37,6 @@ func init() {
viper.SetDefault(TelemetryActiveIntervalKey, TelemetryActiveIntervalDefault)
viper.SetDefault(TelemetryErrorsEnabledKey, TelemetryErrorEnabledDefault)
viper.SetDefault(TelemetryErrorsStageKey, TelemetryErrorsStageDefault)
viper.SetDefault(TelemetryErrorsAddressKey, TelemetryErrorsAddressDefault)
viper.SetEnvPrefix(EnvPrefix)
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.AutomaticEnv()
Expand Down
7 changes: 5 additions & 2 deletions src/shared/telemetries/telemetrysender/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package telemetrysender

import (
"context"
"fmt"
"github.com/Khan/genqlient/graphql"
"github.com/otterize/intents-operator/src/shared/errors"
"github.com/otterize/intents-operator/src/shared/otterizecloud/otterizecloudclient"
"github.com/otterize/intents-operator/src/shared/telemetries/basicbatch"
"github.com/otterize/intents-operator/src/shared/telemetries/telemetriesconfig"
"github.com/otterize/intents-operator/src/shared/telemetries/telemetriesgql"
Expand All @@ -23,10 +25,11 @@ type TelemetrySender struct {
}

func newGqlClient() graphql.Client {
apiAddress := viper.GetString(telemetriesconfig.TelemetryAPIAddressKey)
apiAddress := viper.GetString(otterizecloudclient.OtterizeAPIAddressKey)
graphqlUrl := fmt.Sprintf("%s/telemetry/query", apiAddress)
clientTimeout := viper.GetDuration(telemetriesconfig.TimeoutKey)
clientWithTimeout := &http.Client{Timeout: clientTimeout}
return graphql.NewClient(apiAddress, clientWithTimeout)
return graphql.NewClient(graphqlUrl, clientWithTimeout)
}

func batchSendTelemetries(ctx context.Context, telemetriesClient graphql.Client, telemetries []telemetriesgql.TelemetryInput) error {
Expand Down

0 comments on commit 79fa7a5

Please sign in to comment.