Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Commit

Permalink
Move Metrics to new Relic (#683)
Browse files Browse the repository at this point in the history
* delete prometheus accessor from everywhere

* move all metrics to new relic

* update gemfile

* fix rubocop

* seperate metric for 404

* set correct metric name
  • Loading branch information
FinnIckler authored Sep 12, 2024
1 parent 4853ba5 commit cf72d15
Show file tree
Hide file tree
Showing 18 changed files with 14 additions and 117 deletions.
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ gem 'kredis'
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

# Exposes Metrics
gem 'prometheus_exporter'

# vault for secrets management
gem 'vault'

Expand Down
3 changes: 0 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ GEM
parser (3.3.5.0)
ast (~> 2.4.1)
racc
prometheus_exporter (2.1.1)
webrick
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
Expand Down Expand Up @@ -375,7 +373,6 @@ DEPENDENCIES
money-rails
newrelic_rpm
overcommit
prometheus_exporter
pry
puma (~> 6.4)
rack-cors
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def validate_jwt_token
decoded_token = (JWT.decode token, JwtOptions.secret, true, { algorithm: JwtOptions.algorithm })[0]
@current_user = decoded_token['user_id'].to_i
rescue JWT::VerificationError, JWT::InvalidJtiError
Metrics.jwt_verification_error_counter.increment
Metrics.increment('jwt_verification_error_counter')
render json: { error: ErrorCodes::INVALID_TOKEN }, status: :unauthorized
rescue JWT::ExpiredSignature
render json: { error: ErrorCodes::EXPIRED_TOKEN }, status: :unauthorized
Expand All @@ -37,7 +37,7 @@ def performance_profile(&)
end

def render_error(http_status, error, data = nil)
Metrics.registration_validation_errors_counter.increment
Metrics.increment('registration_validation_errors_counter')
if data.present?
render json: { error: error, data: data }, status: http_status
else
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/registration_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def update
render json: { status: 'ok', registration: process_update(params) }
rescue Dynamoid::Errors::Error => e
Rails.logger.debug e
Metrics.registration_dynamodb_errors_counter.increment
Metrics.increment('registration_dynamodb_errors_counter')
render json: { error: "Error Updating Registration: #{e.message}" },
status: :internal_server_error
end
Expand Down Expand Up @@ -179,7 +179,7 @@ def list
rescue Dynamoid::Errors::Error => e
# Render an error response
Rails.logger.debug e
Metrics.registration_dynamodb_errors_counter.increment
Metrics.increment('registration_dynamodb_errors_counter')
render json: { error: "Error getting registrations #{e}" },
status: :internal_server_error
end
Expand All @@ -193,7 +193,7 @@ def mine
rescue Dynamoid::Errors::Error => e
# Render an error response
Rails.logger.debug e
Metrics.registration_dynamodb_errors_counter.increment
Metrics.increment('registration_dynamodb_errors_counter')
render json: { error: "Error getting registrations #{e}" },
status: :internal_server_error
end
Expand All @@ -212,7 +212,7 @@ def list_admin
render json: add_waiting_list(@competition_id, registrations_with_pii)
rescue Dynamoid::Errors::Error => e
Rails.logger.debug e
Metrics.registration_dynamodb_errors_counter.increment
Metrics.increment('registration_dynamodb_errors_counter')
render json: { error: "Error getting registrations #{e}" },
status: :internal_server_error
end
Expand Down
1 change: 1 addition & 0 deletions app/jobs/registration_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def perform(message)
message[:created_at])
end
Rails.cache.delete("#{message[:user_id]}-registrations-by-user")
Metrics.increment('registrations_processed')
end

private
Expand Down
32 changes: 0 additions & 32 deletions config/initializers/prometheus.rb

This file was deleted.

14 changes: 0 additions & 14 deletions docker-compose.backend-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ services:
- "3001:3000"
environment:
LOCALSTACK_ENDPOINT: "http://localstack:4566"
PROMETHEUS_EXPORTER: "prometheus_exporter"
REDIS_URL: "redis://redis:6379"
RAILS_ENV: test
QUEUE_NAME: "registrations.fifo"
Expand All @@ -23,7 +22,6 @@ services:
- wca-registration
depends_on:
- localstack
- prometheus_exporter
- redis
- wca_registration_worker
healthcheck:
Expand All @@ -32,17 +30,6 @@ services:
# Set the DNS server to be the LocalStack container
- 10.0.2.20


prometheus_exporter:
build:
context: .
dockerfile: dockerfile.metrics
tty: true
ports:
- "9090:9090"
networks:
- wca-registration

wca_registration_worker:
container_name: wca_registration_worker
build:
Expand All @@ -53,7 +40,6 @@ services:
AWS_REGION: "us-east-1"
AWS_ACCESS_KEY_ID: "fake-key"
AWS_SECRET_ACCESS_KEY: "fake-access-key"
PROMETHEUS_EXPORTER: "prometheus_exporter"
DYNAMO_REGISTRATIONS_TABLE: "registrations-development"
QUEUE_NAME: "registrations.fifo"
volumes:
Expand Down
14 changes: 0 additions & 14 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ services:
- "8000:3000"
environment:
LOCALSTACK_ENDPOINT: "http://localstack:4566"
PROMETHEUS_EXPORTER: "prometheus_exporter"
REDIS_URL: "redis://redis:6379"
RAILS_ENV: development
QUEUE_NAME: "registrations.fifo"
Expand All @@ -27,25 +26,13 @@ services:
- wca-main
depends_on:
- localstack
- prometheus_exporter
- redis
healthcheck:
test: curl --fail http://localhost:3000/healthcheck
dns:
# Set the DNS server to be the LocalStack container
- 10.0.2.20

prometheus_exporter:
container_name: prometheus_exporter
build:
context: .
dockerfile: dockerfile.metrics
tty: true
ports:
- "9091:9091"
networks:
- wca-registration


wca_registration_worker:
container_name: wca_registration_worker
Expand All @@ -57,7 +44,6 @@ services:
AWS_REGION: "us-east-1"
AWS_ACCESS_KEY_ID: "fake-key"
AWS_SECRET_ACCESS_KEY: "fake-access-key"
PROMETHEUS_EXPORTER: "prometheus_exporter"
DYNAMO_REGISTRATIONS_TABLE: "registrations-development"
REGISTRATION_HISTORY_DYNAMO_TABLE: "registration-history-development"
CODE_ENVIRONMENT: "development"
Expand Down
8 changes: 0 additions & 8 deletions dockerfile.metrics

This file was deleted.

1 change: 0 additions & 1 deletion env_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
end
# We even need the AWS_REGION in dev because we fake authenticate with localstack
mandatory :AWS_REGION, :string
mandatory :PROMETHEUS_EXPORTER, :string
mandatory :DYNAMO_REGISTRATIONS_TABLE, :string
mandatory :REGISTRATION_HISTORY_DYNAMO_TABLE, :string
mandatory :WAITING_LIST_DYNAMO_TABLE, :string
Expand Down
4 changes: 0 additions & 4 deletions infra/handler/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ locals {
name = "QUEUE_NAME",
value = var.shared_resources.queue.name
},
{
name = "PROMETHEUS_EXPORTER"
value = var.prometheus_address
},
{
name = "REDIS_URL"
value = "redis://${var.shared_resources.aws_elasticache_cluster.cache_nodes.0.address}:${var.shared_resources.aws_elasticache_cluster.cache_nodes.0.port}"
Expand Down
6 changes: 0 additions & 6 deletions infra/handler/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ variable "vault_address" {
default = "http://vault.worldcubeassociation.org:8200"
}

variable "prometheus_address" {
type = string
description = "The Address that prometheus is running at"
default = "prometheus.worldcubeassociation.org"
}

variable "name_prefix" {
type = string
description = "Prefix for naming resources"
Expand Down
4 changes: 0 additions & 4 deletions infra/staging/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ locals {
name = "WAITING_LIST_DYNAMO_TABLE",
value = aws_dynamodb_table.waiting_list.name
},
{
name = "PROMETHEUS_EXPORTER"
value = var.prometheus_address
},
{
name = "REDIS_URL"
value = "redis://${aws_elasticache_cluster.this.cache_nodes.0.address}:${aws_elasticache_cluster.this.cache_nodes.0.port}"
Expand Down
6 changes: 0 additions & 6 deletions infra/staging/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ variable "vault_address" {
default = "http://vault.worldcubeassociation.org:8200"
}

variable "prometheus_address" {
type = string
description = "The Address that prometheus is running at"
default = "prometheus.worldcubeassociation.org"
}

variable "region" {
type = string
description = "The region to operate in"
Expand Down
4 changes: 0 additions & 4 deletions infra/worker/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ locals {
name = "REGISTRATION_LIVE_SITE",
value = "true"
},
{
name = "PROMETHEUS_EXPORTER"
value = var.prometheus_address
},
{
name = "TASK_ROLE"
value = aws_iam_role.task_role.name
Expand Down
5 changes: 0 additions & 5 deletions infra/worker/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ variable "region" {
description = "The region to operate in"
default = "us-west-2"
}
variable "prometheus_address" {
type = string
description = "The Address that prometheus is running at"
default = "prometheus.worldcubeassociation.org"
}

variable "availability_zones" {
type = list(string)
Expand Down
8 changes: 4 additions & 4 deletions lib/competition_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def self.fetch_qualifications(competition_id)
@status = 200
response.parsed_response
when 404
Metrics.registration_competition_api_error_counter.increment
Metrics.increment('registration_competition_api_404_counter')
raise RegistrationError.new(404, ErrorCodes::COMPETITION_NOT_FOUND)
else
Metrics.registration_competition_api_error_counter.increment
Metrics.increment('registration_competition_api_error_counter')
raise RegistrationError.new(response.code.to_i, ErrorCodes::COMPETITION_API_5XX)
end
end
Expand All @@ -45,10 +45,10 @@ def self.fetch_qualifications(competition_id)
when 200
response.parsed_response
when 404
Metrics.registration_competition_api_error_counter.increment
Metrics.increment('registration_competition_api_404_counter')
raise RegistrationError.new(404, ErrorCodes::COMPETITION_NOT_FOUND)
else
Metrics.registration_competition_api_error_counter.increment
Metrics.increment('registration_competition_api_error_counter')
raise RegistrationError.new(response.code.to_i, ErrorCodes::COMPETITION_API_5XX)
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/metrics.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

module Metrics
class << self
attr_accessor :registration_validation_errors_counter, :registration_dynamodb_errors_counter, :registrations_counter, :registration_competition_api_error_counter, :registration_competitor_api_error_counter,
:registration_impersonation_attempt_counter, :jwt_verification_error_counter
def self.increment(metric)
return if Rails.env.local?
::NewRelic::Agent.increment_metric("Custom/Registration/#{metric}")
end
end

0 comments on commit cf72d15

Please sign in to comment.