Skip to content

Commit

Permalink
event-reporter: added runtime version reporting with each event
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-codefresh committed Nov 20, 2024
1 parent 06395af commit 5d9da4f
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 94 deletions.
11 changes: 7 additions & 4 deletions cmd/event-reporter-server/commands/event_reporter_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func NewCommand() *cobra.Command {
codefreshUrl string
codefreshToken string
shardingAlgorithm string
runtimeVersion string
rootpath string
useGrpc bool

Expand Down Expand Up @@ -179,10 +180,11 @@ func NewCommand() *cobra.Command {
ApplicationNamespaces: applicationNamespaces,
ApplicationServiceClient: getApplicationClient(useGrpc, applicationServerAddress, argocdToken, rootpath),
CodefreshConfig: &codefresh.CodefreshConfig{
BaseURL: codefreshUrl,
AuthToken: codefreshToken,
TlsInsecure: codefreshTlsInsecure,
CaCertPath: codefreshTlsCertPath,
BaseURL: codefreshUrl,
AuthToken: codefreshToken,
TlsInsecure: codefreshTlsInsecure,
CaCertPath: codefreshTlsCertPath,
RuntimeVersion: runtimeVersion,
},
RateLimiterOpts: &reporter.RateLimiterOpts{
Enabled: rateLimiterEnabled,
Expand Down Expand Up @@ -236,6 +238,7 @@ func NewCommand() *cobra.Command {
command.Flags().StringVar(&codefreshUrl, "codefresh-url", env.StringFromEnv("CODEFRESH_URL", "https://g.codefresh.io"), "Codefresh API url")
command.Flags().StringVar(&codefreshToken, "codefresh-token", env.StringFromEnv("CODEFRESH_TOKEN", ""), "Codefresh token")
command.Flags().StringVar(&shardingAlgorithm, "sharding-method", env.StringFromEnv(common.EnvEventReporterShardingAlgorithm, common.DefaultEventReporterShardingAlgorithm), "Enables choice of sharding method. Supported sharding methods are : [legacy] ")
command.Flags().StringVar(&runtimeVersion, "codefresh-runtime-version", env.StringFromEnv("CODEFRESH_RUNTIME_VERSION", ""), "Codefresh runtime version to be reported with each event to platform")
command.Flags().StringSliceVar(&applicationNamespaces, "application-namespaces", env.StringsFromEnv("ARGOCD_APPLICATION_NAMESPACES", []string{}, ","), "List of additional namespaces where application resources can be managed in")
command.Flags().BoolVar(&useGrpc, "grpc", env.ParseBoolFromEnv("USE_GRPC", false), "Use grpc for interact with argocd server")
command.Flags().BoolVar(&rateLimiterEnabled, "rate-limiter-enabled", env.ParseBoolFromEnv("RATE_LIMITER_ENABLED", false), "Use rate limiter for prevent queue to be overflowed")
Expand Down
5 changes: 4 additions & 1 deletion event_reporter/reporter/application_event_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type applicationEventReporter struct {
applicationServiceClient appclient.ApplicationClient
metricsServer *metrics.MetricsServer
db db.ArgoDB
runtimeVersion string
}

type ApplicationEventReporter interface {
Expand All @@ -66,6 +67,7 @@ func NewApplicationEventReporter(cache *servercache.Cache, applicationServiceCli
appLister: appLister,
metricsServer: metricsServer,
db: db,
runtimeVersion: codefreshConfig.RuntimeVersion,
}
}

Expand Down Expand Up @@ -201,7 +203,7 @@ func (s *applicationEventReporter) StreamApplicationEvents(
} else {
// will get here only for root applications (not managed as a resource by another application)
logCtx.Info("processing as root application")
appEvent, err := s.getApplicationEventPayload(ctx, a, appTree, eventProcessingStartedAt, applicationVersions, argoTrackingMetadata)
appEvent, err := s.getApplicationEventPayload(ctx, a, appTree, eventProcessingStartedAt, applicationVersions, argoTrackingMetadata, s.runtimeVersion)
if err != nil {
s.metricsServer.IncErroredEventsCounter(metrics.MetricParentAppEventType, metrics.MetricEventGetPayloadErrorType, a.Name)
return fmt.Errorf("failed to get application event: %w", err)
Expand Down Expand Up @@ -363,6 +365,7 @@ func (s *applicationEventReporter) processResource(
desiredManifests: reportedEntityParentApp.desiredManifests,
},
argoTrackingMetadata,
s.runtimeVersion,
)
if err != nil {
s.metricsServer.IncErroredEventsCounter(metricsEventType, metrics.MetricEventGetPayloadErrorType, reportedEntityParentApp.app.Name)
Expand Down
24 changes: 14 additions & 10 deletions event_reporter/reporter/event_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func getResourceEventPayload(
rr *ReportedResource,
reportedEntityParentApp *ReportedEntityParentApp,
argoTrackingMetadata *ArgoTrackingMetadata,
runtimeVersion string,
) (*events.Event, error) {
var (
err error
Expand Down Expand Up @@ -136,11 +137,12 @@ func getResourceEventPayload(
}

payload := events.EventPayload{
Timestamp: appEventProcessingStartedAt,
Object: object,
Source: &source,
Errors: getResourceEventPayloadErrors(rr, reportedEntityParentApp),
AppVersions: applicationVersionsEvents,
Timestamp: appEventProcessingStartedAt,
Object: object,
Source: &source,
Errors: getResourceEventPayloadErrors(rr, reportedEntityParentApp),
AppVersions: applicationVersionsEvents,
RuntimeVersion: runtimeVersion,
}

if payload.AppVersions != nil {
Expand Down Expand Up @@ -289,6 +291,7 @@ func (s *applicationEventReporter) getApplicationEventPayload(
eventProcessingStartedAt string,
applicationVersions *apiclient.ApplicationVersions,
argoTrackingMetadata *ArgoTrackingMetadata,
runtimeVersion string,
) (*events.Event, error) {
var (
syncStarted = metav1.Now()
Expand Down Expand Up @@ -365,11 +368,12 @@ func (s *applicationEventReporter) getApplicationEventPayload(
errors = append(errors, parseAggregativeHealthErrorsOfApplication(a, appTree)...)

payload := events.EventPayload{
Timestamp: eventProcessingStartedAt,
Object: object,
Source: source,
Errors: errors,
AppVersions: applicationVersionsEvents,
Timestamp: eventProcessingStartedAt,
Object: object,
Source: source,
Errors: errors,
AppVersions: applicationVersionsEvents,
RuntimeVersion: runtimeVersion,
}

logCtx.Infof("AppVersion before encoding: %v", utils.SafeString(payload.AppVersions.AppVersion))
Expand Down
Loading

0 comments on commit 5d9da4f

Please sign in to comment.