Skip to content

Commit

Permalink
Fix token auth for teamcity integration (#17478)
Browse files Browse the repository at this point in the history
* check for auth_token key and skip adding guestAuth or httpAuth to url if present

* add changelog
  • Loading branch information
gbx-andrew-schneider committed May 15, 2024
1 parent 971d081 commit a026087
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions teamcity/changelog.d/17478.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
check for auth_token key and skip adding guestAuth or httpAuth to url if present
12 changes: 8 additions & 4 deletions teamcity/datadog_checks/teamcity/teamcity_openmetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ class TeamCityOpenMetrics(OpenMetricsBaseCheckV2):
__NAMESPACE__ = 'teamcity'
DEFAULT_METRIC_LIMIT = 0

DEFAULT_METRICS_URL = "/{}/app/metrics"
EXPERIMENTAL_METRICS_URL = "/{}/app/metrics?experimental=true"
DEFAULT_METRICS_URL = "/app/metrics"
EXPERIMENTAL_METRICS_URL = "/app/metrics?experimental=true"

def __init__(self, name, init_config, instances):
super(TeamCityOpenMetrics, self).__init__(name, init_config, instances)
self.basic_http_auth = is_affirmative(
self.instance.get('basic_http_authentication', bool(self.instance.get('password')))
)
self.token_auth = is_affirmative(self.instance.get('auth_token'))
self.auth_type = 'httpAuth' if self.basic_http_auth else 'guestAuth'
parsed_endpoint = urlparse(self.instance.get('server'))
self.server_url = "{}://{}".format(parsed_endpoint.scheme, parsed_endpoint.netloc)
Expand All @@ -29,9 +30,12 @@ def __init__(self, name, init_config, instances):
experimental_metrics = is_affirmative(self.instance.get('experimental_metrics', False))

if experimental_metrics:
self.metrics_endpoint = self.EXPERIMENTAL_METRICS_URL.format(self.auth_type)
self.metrics_endpoint = self.EXPERIMENTAL_METRICS_URL
else:
self.metrics_endpoint = self.DEFAULT_METRICS_URL.format(self.auth_type)
self.metrics_endpoint = self.DEFAULT_METRICS_URL

if not self.token_auth:
self.metrics_endpoint = '/{}{}'.format(self.auth_type, self.metrics_endpoint)

def configure_scrapers(self):
config = deepcopy(self.instance)
Expand Down
5 changes: 4 additions & 1 deletion teamcity/datadog_checks/teamcity/teamcity_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, name, init_config, instances):
self.basic_http_auth = is_affirmative(
self.instance.get('basic_http_authentication', bool(self.instance.get('password', False)))
)
self.token_auth = is_affirmative(self.instance.get('auth_token'))

self.monitored_projects = self.instance.get('projects', {})
self.default_build_configs_limit = self.instance.get('default_build_configs_limit', DEFAULT_BUILD_CONFIGS_LIMIT)
Expand All @@ -67,7 +68,9 @@ def __init__(self, name, init_config, instances):

server = self.instance.get('server')
self.server_url = normalize_server_url(server)
self.base_url = "{}/{}".format(self.server_url, self.auth_type)
self.base_url = self.server_url
if not self.token_auth:
self.base_url = "{}/{}".format(self.server_url, self.auth_type)

instance_tags = [
'server:{}'.format(sanitize_server_url(self.server_url)),
Expand Down

0 comments on commit a026087

Please sign in to comment.