Power Metrics as StarlingX application

This commit creates the StarlingX application for Power Metrics.

Test Plan (AIO-SX, AIO-DX, STD):
PASS: The application can be successfully installed
PASS: The label "app.starlingx.io/component" was applied to pods
PASS: Use curl to verify that cadvisor metrics are being generated:
      curl cadvisor.power-metrics.svc.cluster.local:80/metrics
PASS: Use curl to verify that telegraf metrics are being generated:
      curl telegraf.power-metrics.svc.cluster.local:9273/metrics
PASS: The application can be successfully uninstalled
PASS: The power-metrics namespace is deleted on uninstall

Story: 2010773
Task: 48498

Change-Id: Ife077f4baf4b81934ddfeeb3b21ea539e8975ba1
Signed-off-by: Alyson Deives Pereira <alyson.deivespereira@windriver.com>
Co-authored-by: Caio Cesar Ferreira <caio.cesarferreira@windriver.com>
Co-authored-by: Fabio Studyny Higa <fabio.studynyhiga@windriver.com>
This commit is contained in:
Alyson Deives Pereira 2023-07-28 17:56:06 -03:00
parent cb99efbc02
commit c1633607e5
85 changed files with 3274 additions and 5 deletions

View File

@ -5,6 +5,76 @@
check:
jobs:
- openstack-tox-linters
- k8sapp-power-metrics-tox-py39
- k8sapp-power-metrics-tox-flake8
- k8sapp-power-metrics-tox-pylint
- k8sapp-power-metrics-tox-bandit
gate:
jobs:
- openstack-tox-linters
- k8sapp-power-metrics-tox-py39
- k8sapp-power-metrics-tox-flake8
- k8sapp-power-metrics-tox-pylint
- k8sapp-power-metrics-tox-bandit
- job:
name: k8sapp-power-metrics-tox-py39
parent: tox-py39
description: |
Run py39 for power-metrics app
nodeset: debian-bullseye
required-projects:
- starlingx/config
- starlingx/fault
- starlingx/root
- starlingx/update
- starlingx/utilities
files:
- python3-k8sapp-power-metrics/*
vars:
tox_envlist: py39
tox_extra_args: -c python3-k8sapp-power-metrics/k8sapp_power_metrics/tox.ini
tox_constraints_file: '{{ ansible_user_dir }}/src/opendev.org/starlingx/root/build-tools/requirements/debian/upper-constraints.txt'
- job:
name: k8sapp-power-metrics-tox-flake8
parent: tox
description: |
Run flake8 for power-metrics
nodeset: debian-bullseye
files:
- python3-k8sapp-power-metrics/*
vars:
tox_envlist: flake8
tox_extra_args: -c python3-k8sapp-power-metrics/k8sapp_power_metrics/tox.ini
- job:
name: k8sapp-power-metrics-tox-pylint
parent: tox
description: |
Run pylint test for k8sapp_power_metrics
required-projects:
- starlingx/config
- starlingx/fault
- starlingx/root
- starlingx/update
- starlingx/utilities
nodeset: debian-bullseye
files:
- python3-k8sapp-power-metrics/*
vars:
tox_envlist: pylint
tox_extra_args: -c python3-k8sapp-power-metrics/k8sapp_power_metrics/tox.ini
tox_constraints_file: '{{ ansible_user_dir }}/src/opendev.org/starlingx/root/build-tools/requirements/debian/upper-constraints.txt'
- job:
name: k8sapp-power-metrics-tox-bandit
parent: tox
description: |
Run bandit for power-metrics
nodeset: debian-bullseye
files:
- python3-k8sapp-power-metrics/*
vars:
tox_envlist: bandit
tox_extra_args: -c python3-k8sapp-power-metrics/k8sapp_power_metrics/tox.ini

17
HACKING.rst Normal file
View File

@ -0,0 +1,17 @@
StarlingX App-power-metrics Style Commandments
==============================================
- Step 1: Read the OpenStack style commandments
https://docs.openstack.org/hacking/latest/
- Step 2: Read on
App-power-metrics Specific Commandments
---------------------------------------
None so far
Running tests
-------------
The approach to running tests is to simply run the command ``tox``. This will
create virtual environments, populate them with dependencies and run all of
the tests that OpenStack CI systems run.

10
bindep.txt Normal file
View File

@ -0,0 +1,10 @@
# This is a cross-platform list tracking distribution packages needed for install and tests;
# see https://docs.openstack.org/infra/bindep/ for additional information.
libffi-dev [platform:dpkg]
libldap2-dev [platform:dpkg]
libxml2-dev [platform:dpkg]
libxslt1-dev [platform:dpkg]
libsasl2-dev [platform:dpkg]
libffi-devel [platform:rpm]
python3-all-dev [platform:dpkg]

1
debian_build_layer.cfg Normal file
View File

@ -0,0 +1 @@
flock

2
debian_iso_image.inc Normal file
View File

@ -0,0 +1,2 @@
#stx-power-metrics-helm
stx-power-metrics-helm

3
debian_pkg_dirs Normal file
View File

@ -0,0 +1,3 @@
telegraf-helm
python3-k8sapp-power-metrics
stx-power-metrics-helm

View File

@ -0,0 +1 @@
stx-power-metrics-images

View File

@ -0,0 +1,5 @@
python3-k8sapp-power-metrics (1.0-1) unstable; urgency=medium
* Initial release.
-- Alyson Deives Pereira <alyson.deivespereira@windriver.com> Thu, 6 Jul 2023 12:35:25 +0000

View File

@ -0,0 +1,26 @@
Source: python3-k8sapp-power-metrics
Section: libs
Priority: optional
Maintainer: StarlingX Developers <starlingx-discuss@lists.starlingx.io>
Build-Depends: debhelper-compat (= 13),
dh-python,
python3-all,
python3-pbr,
python3-setuptools,
python3-wheel
Standards-Version: 4.5.1
Homepage: https://www.starlingx.io
Package: python3-k8sapp-power-metrics
Section: libs
Architecture: any
Depends: ${misc:Depends}, ${python3:Depends}
Description: StarlingX Sysinv Power Metrics Extensions
This package contains sysinv plugins for the power metrics K8S app.
Package: python3-k8sapp-power-metrics-wheels
Section: libs
Architecture: any
Depends: ${misc:Depends}, ${python3:Depends}, python3-wheel
Description: StarlingX Sysinv Power Metrics Extension Wheels
This package contains python wheels for the power metrics K8S app plugins.

View File

@ -0,0 +1,41 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: python3-k8sapp-power-metrics
Source: https://opendev.org/starlingx/app-power-metrics/
Files: *
Copyright: (c) 2023 Wind River Systems, Inc
License: Apache-2
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
.
https://www.apache.org/licenses/LICENSE-2.0
.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
.
On Debian-based systems the full text of the Apache version 2.0 license
can be found in `/usr/share/common-licenses/Apache-2.0'.
# If you want to use GPL v2 or later for the /debian/* files use
# the following clauses, or change it to suit. Delete these two lines
Files: debian/*
Copyright: 2023 Wind River Systems, Inc
License: Apache-2
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
.
https://www.apache.org/licenses/LICENSE-2.0
.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
.
On Debian-based systems the full text of the Apache version 2.0 license
can be found in `/usr/share/common-licenses/Apache-2.0'.

View File

@ -0,0 +1 @@
usr/lib/python3/dist-packages/k8sapp_*

View File

@ -0,0 +1,31 @@
#!/usr/bin/make -f
# export DH_VERBOSE = 1
export APP_NAME = power-metrics
export PYBUILD_NAME = k8sapp-power-metrics
export DEB_VERSION = $(shell dpkg-parsechangelog | egrep '^Version:' | cut -f 2 -d ' ')
export MAJOR = $(shell echo $(DEB_VERSION) | cut -f 1 -d '-')
export MINOR_PATCH = $(shell echo $(DEB_VERSION) | cut -f 4 -d '.')
export PBR_VERSION = $(MAJOR).$(MINOR_PATCH)
export ROOT = $(CURDIR)/debian/tmp
export SKIP_PIP_INSTALL = 1
%:
dh $@ --with=python3 --buildsystem=pybuild
override_dh_auto_install:
python3 setup.py install \
--install-layout=deb \
--root $(ROOT)
python3 setup.py bdist_wheel \
--universal \
-d $(ROOT)/plugins
override_dh_python3:
dh_python3 --shebang=/usr/bin/python3
override_dh_auto_test:
PYTHONDIR=$(CURDIR) stestr run

View File

@ -0,0 +1 @@
3.0 (quilt)

View File

@ -0,0 +1,9 @@
---
debname: python3-k8sapp-power-metrics
debver: 1.0-1
src_path: k8sapp_power_metrics
revision:
dist: $STX_DIST
GITREVCOUNT:
SRC_DIR: ${MY_REPO}/stx/app-power-metrics
BASE_SRCREV: 5304930dae1e62dbea8cdc59d756b2b1fcae76a5

View File

@ -0,0 +1,35 @@
# Compiled files
*.py[co]
*.a
*.o
*.so
# Sphinx
_build
doc/source/api/
# Packages/installer info
*.egg
*.egg-info
dist
build
eggs
parts
var
sdist
develop-eggs
.installed.cfg
# Other
*.DS_Store
.stestr
.testrepository
.tox
.venv
.*.swp
.coverage
bandit.xml
cover
AUTHORS
ChangeLog
*.sqlite

View File

@ -0,0 +1,4 @@
[DEFAULT]
test_path=./k8sapp_power_metrics/tests
top_dir=./k8sapp_power_metrics
#parallel_class=True

View File

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2019 Wind River Systems, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -0,0 +1,7 @@
k8sapp-power-metrics
===================
This project contains StarlingX Kubernetes application specific python plugins
for Power Metrics. These plugins are required to integrate the Power Metrics
application into the StarlingX application framework and to support the
various StarlingX deployments.

View File

@ -0,0 +1,26 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# Helm: Supported charts:
# These values match the names in the chart package's Chart.yaml
HELM_CHART_CADVISOR = 'cadvisor'
HELM_CHART_TELEGRAF = 'telegraf'
# FluxCD
FLUXCD_HELM_RELEASE_CADVISOR = 'cadvisor'
FLUXCD_HELM_RELEASE_TELEGRAF = 'telegraf'
# Namespace to deploy the application
HELM_NS_PM = 'power-metrics'
# Application Name
HELM_APP_PM = 'power-metrics'
# Application component label
HELM_LABEL_PARAMETER = 'podLabels'
HELM_COMPONENT_LABEL = 'app.starlingx.io/component'
HELM_COMPONENT_LABEL_VALUE_PLATFORM = 'platform'
HELM_COMPONENT_LABEL_VALUE_APPLICATION = 'application'

View File

@ -0,0 +1,105 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import yaml
from oslo_log import log as logging
from sysinv.common import exception
from sysinv.db import api as dbapi
from sysinv.helm import base
from k8sapp_power_metrics.common import constants as app_constants
LOG = logging.getLogger(__name__)
class CadvisorHelm(base.FluxCDBaseHelm):
"""Class to encapsulate helm operations for the power metrics chart"""
SUPPORTED_NAMESPACES = base.FluxCDBaseHelm.SUPPORTED_NAMESPACES + \
[app_constants.HELM_NS_PM]
SUPPORTED_APP_NAMESPACES = {
app_constants.HELM_APP_PM: SUPPORTED_NAMESPACES
}
SERVICE_NAME = app_constants.HELM_APP_PM
SUPPORTED_COMPONENT_OVERRIDES = [
app_constants.HELM_COMPONENT_LABEL_VALUE_PLATFORM,
app_constants.HELM_COMPONENT_LABEL_VALUE_APPLICATION
]
DEFAULT_AFFINITY = app_constants.HELM_COMPONENT_LABEL_VALUE_PLATFORM
@property
def CHART(self):
return app_constants.HELM_CHART_CADVISOR
@property
def HELM_RELEASE(self):
return app_constants.FLUXCD_HELM_RELEASE_CADVISOR
def get_namespaces(self):
return self.SUPPORTED_NAMESPACES
def get_overrides(self, namespace=None):
dbapi_instance = dbapi.get_instance()
db_app = dbapi_instance.kube_app_get(app_constants.HELM_APP_PM)
# User chart overrides
chart_overrides = self._get_helm_overrides(
dbapi_instance,
db_app,
self.CHART,
app_constants.HELM_NS_PM,
'user_overrides')
user_affinity = chart_overrides.get(app_constants.HELM_COMPONENT_LABEL,
self.DEFAULT_AFFINITY)
if user_affinity in self.SUPPORTED_COMPONENT_OVERRIDES:
affinity = user_affinity
else:
LOG.warn(f"User override value {user_affinity} "
f"for {app_constants.HELM_COMPONENT_LABEL} is invalid, "
f"using default value {self.DEFAULT_AFFINITY}")
affinity = self.DEFAULT_AFFINITY
overrides = {
app_constants.HELM_NS_PM: {
app_constants.HELM_LABEL_PARAMETER: {
app_constants.HELM_COMPONENT_LABEL: affinity
}
}
}
if namespace in self.SUPPORTED_NAMESPACES:
return overrides[namespace]
if namespace:
raise exception.InvalidHelmNamespace(chart=self.CHART,
namespace=namespace)
return overrides
@staticmethod
def _get_helm_overrides(dbapi_instance, app, chart, namespace,
type_of_overrides):
"""Helper function for querying helm overrides from db."""
helm_overrides = {}
try:
overrides = dbapi_instance.helm_override_get(
app_id=app.id,
name=chart,
namespace=namespace,
)[type_of_overrides]
if isinstance(overrides, str):
helm_overrides = yaml.safe_load(overrides)
except exception.HelmOverrideNotFound:
LOG.debug("Overrides for this chart not found, nothing to be done.")
return helm_overrides

View File

@ -0,0 +1,105 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import yaml
from oslo_log import log as logging
from sysinv.common import exception
from sysinv.db import api as dbapi
from sysinv.helm import base
from k8sapp_power_metrics.common import constants as app_constants
LOG = logging.getLogger(__name__)
class TelegrafHelm(base.FluxCDBaseHelm):
"""Class to encapsulate helm operations for the power metrics chart"""
SUPPORTED_NAMESPACES = base.FluxCDBaseHelm.SUPPORTED_NAMESPACES + \
[app_constants.HELM_NS_PM]
SUPPORTED_APP_NAMESPACES = {
app_constants.HELM_APP_PM: SUPPORTED_NAMESPACES,
}
SERVICE_NAME = app_constants.HELM_APP_PM
SUPPORTED_COMPONENT_OVERRIDES = [
app_constants.HELM_COMPONENT_LABEL_VALUE_PLATFORM,
app_constants.HELM_COMPONENT_LABEL_VALUE_APPLICATION
]
DEFAULT_AFFINITY = app_constants.HELM_COMPONENT_LABEL_VALUE_PLATFORM
@property
def CHART(self):
return app_constants.HELM_CHART_TELEGRAF
@property
def HELM_RELEASE(self):
return app_constants.FLUXCD_HELM_RELEASE_TELEGRAF
def get_namespaces(self):
return self.SUPPORTED_NAMESPACES
def get_overrides(self, namespace=None):
dbapi_instance = dbapi.get_instance()
db_app = dbapi_instance.kube_app_get(app_constants.HELM_APP_PM)
# User chart overrides
chart_overrides = self._get_helm_overrides(
dbapi_instance,
db_app,
self.CHART,
app_constants.HELM_NS_PM,
'user_overrides')
user_affinity = chart_overrides.get(app_constants.HELM_COMPONENT_LABEL,
self.DEFAULT_AFFINITY)
if user_affinity in self.SUPPORTED_COMPONENT_OVERRIDES:
affinity = user_affinity
else:
LOG.warn(f"User override value {user_affinity} "
f"for {app_constants.HELM_COMPONENT_LABEL} is invalid, "
f"using default value {self.DEFAULT_AFFINITY}")
affinity = self.DEFAULT_AFFINITY
overrides = {
app_constants.HELM_NS_PM: {
app_constants.HELM_LABEL_PARAMETER: {
app_constants.HELM_COMPONENT_LABEL: affinity
}
}
}
if namespace in self.SUPPORTED_NAMESPACES:
return overrides[namespace]
if namespace:
raise exception.InvalidHelmNamespace(chart=self.CHART,
namespace=namespace)
return overrides
@staticmethod
def _get_helm_overrides(dbapi_instance, app, chart, namespace,
type_of_overrides):
"""Helper function for querying helm overrides from db."""
helm_overrides = {}
try:
overrides = dbapi_instance.helm_override_get(
app_id=app.id,
name=chart,
namespace=namespace,
)[type_of_overrides]
if isinstance(overrides, str):
helm_overrides = yaml.safe_load(overrides)
except exception.HelmOverrideNotFound:
LOG.debug("Overrides for this chart not found, nothing to be done.")
return helm_overrides

View File

@ -0,0 +1,50 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# All Rights Reserved.
#
""" System inventory App lifecycle operator."""
from oslo_log import log as logging
from sysinv.common import constants as c
from sysinv.helm import lifecycle_base as base
from sysinv.helm import lifecycle_utils
from k8sapp_power_metrics.common import constants as app_constants
LOG = logging.getLogger(__name__)
class PowerMetricsAppLifecycleOperator(base.AppLifecycleOperator):
def app_lifecycle_actions(self, context, conductor_obj,
app_op, app, hook_info):
"""Perform lifecycle actions for an operation
:param context: request context, can be None
:param conductor_obj: conductor object, can be None
:param app_op: AppOperator object
:param app: AppOperator.Application object
:param hook_info: LifecycleHookInfo object
"""
if hook_info.lifecycle_type == c.APP_LIFECYCLE_TYPE_OPERATION:
if hook_info.operation == c.APP_REMOVE_OP:
if hook_info.relative_timing == c.APP_LIFECYCLE_TIMING_POST:
self._post_remove(app_op)
super().app_lifecycle_actions(context, conductor_obj,
app_op, app, hook_info)
@staticmethod
def _post_remove(app_op):
# Helm doesn't delete the namespace. To clean up after
# application-remove, we need to explicitly delete it.
LOG.debug(f"Executing post_remove for {app_constants.HELM_APP_PM} app")
lifecycle_utils.delete_namespace(app_op, app_constants.HELM_NS_PM)

View File

@ -0,0 +1,45 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
from sysinv.tests.db import base as dbbase
from k8sapp_power_metrics.common import constants as app_constants
class K8SAppPowerMetricsAppMixin(object):
app_name = app_constants.HELM_APP_PM
path_name = app_name + '.tgz'
# pylint: disable=invalid-name,useless-parent-delegation
def setUp(self):
super().setUp()
def test_stub(self):
# Replace this with a real unit test.
pass
# Test Configuration:
# - Controller
# - IPv6
# - Ceph Storage
# - power-metrics app
class K8sAppPowerMetricsControllerTestCase(K8SAppPowerMetricsAppMixin,
dbbase.BaseIPv6Mixin,
dbbase.BaseCephStorageBackendMixin,
dbbase.ControllerHostTestCase):
pass
# Test Configuration:
# - AIO
# - IPv4
# - Ceph Storage
# - power-metrics app
class K8SAppPowerMetricsAIOTestCase(K8SAppPowerMetricsAppMixin,
dbbase.BaseCephStorageBackendMixin,
dbbase.AIOSimplexHostTestCase):
pass

View File

@ -0,0 +1,28 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
from sysinv.db import api as dbapi
from sysinv.tests.db import base as dbbase
from sysinv.tests.db import utils as dbutils
from sysinv.tests.helm import base
from k8sapp_power_metrics.tests import test_plugins
class PowerMetricsTestCase(test_plugins.K8SAppPowerMetricsAppMixin,
base.HelmTestCaseMixin):
def setUp(self):
super().setUp()
self.app = dbutils.create_test_app(name='power-metrics')
self.dbapi = dbapi.get_instance()
class PowerMetricsTestCaseDummy(PowerMetricsTestCase,
dbbase.ProvisionedControllerHostTestCase):
# without a test zuul will fail
def test_dummy(self):
pass

View File

@ -0,0 +1,234 @@
[MASTER]
# Specify a configuration file.
rcfile=pylint.rc
# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
#init-hook=
# Add files or directories to the blacklist. Should be base names, not paths.
ignore=
# Pickle collected data for later comparisons.
persistent=yes
# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=pylint.extensions.bad_builtin
# Use multiple processes to speed up Pylint.
jobs=4
# Allow loading of arbitrary C extensions. Extensions are imported into the
# active Python interpreter and may run arbitrary code.
unsafe-load-any-extension=no
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code
extension-pkg-whitelist=lxml.etree,greenlet
[MESSAGES CONTROL]
# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once).
# See "Messages Control" section of
# https://pylint.readthedocs.io/en/latest/user_guide
disable=
# C codes refer to Convention
C0114, # missing-module-docstring
C0115, # missing-class-docstring
C0116, # missing-function-docstring
# R codes refer to refactoring
R0205, # useless-object-inheritance
R0901, # too-many-ancestors
R0903, # too-few-public-methods
R0913, # too-many-arguments
# W codes are warnings
W0212, # protected-access
[REPORTS]
# Set the output format. Available formats are text, parseable, colorized, msvs
# (visual studio) and html
output-format=text
# Tells whether to display a full report or only the messages
reports=no
# Python expression which should return a note less than 10 (10 is the highest
# note). You have access to the variables errors warning, statement which
# respectively contain the number of errors / warnings messages and the total
# number of statements analyzed. This is used by the global evaluation report
# (RP0004).
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
[SIMILARITIES]
# Minimum lines number of a similarity.
min-similarity-lines=4
# Ignore comments when computing similarities.
ignore-comments=yes
# Ignore docstrings when computing similarities.
ignore-docstrings=yes
[FORMAT]
# Maximum number of characters on a single line.
max-line-length=85
# Maximum number of lines in a module
max-module-lines=1000
# String used as indentation unit. This is usually 4 spaces or "\t" (1 tab).
indent-string=' '
[TYPECHECK]
# Tells whether missing members accessed in mixin class should be ignored. A
# mixin class is detected if its name ends with "mixin" (case insensitive).
ignore-mixin-members=yes
# List of module names for which member attributes should not be checked
# (useful for modules/projects where namespaces are manipulated during runtime
# and thus existing member attributes cannot be deduced by static analysis
ignored-modules=distutils,eventlet.green.subprocess,six,six.moves
# List of classes names for which member attributes should not be checked
# (useful for classes with attributes dynamically set).
# pylint is confused by sqlalchemy Table, as well as sqlalchemy Enum types
# ie: (unprovisioned, identity)
# LookupDict in requests library confuses pylint
ignored-classes=SQLObject, optparse.Values, thread._local, _thread._local,
Table, unprovisioned, identity, LookupDict
# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E0201 when accessed. Python regular
# expressions are accepted.
generated-members=REQUEST,acl_users,aq_parent
[BASIC]
# Regular expression which should only match correct module names
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
# Regular expression which should only match correct module level names
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
# Regular expression which should only match correct class names
class-rgx=[A-Z_][a-zA-Z0-9]+$
# Regular expression which should only match correct function names
function-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct method names
method-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct instance attribute names
attr-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct argument names
argument-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct variable names
variable-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct list comprehension /
# generator expression variable names
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
# Good variable names which should always be accepted, separated by a comma
good-names=i,j,k,ex,Run,_
# Bad variable names which should always be refused, separated by a comma
bad-names=foo,bar,baz,toto,tutu,tata
# Regular expression which should only match functions or classes name which do
# not require a docstring
no-docstring-rgx=__.*__
[MISCELLANEOUS]
# List of note tags to take in consideration, separated by a comma.
notes=FIXME,XXX,TODO
[VARIABLES]
# Tells whether we should check for unused import in __init__ files.
init-import=no
# A regular expression matching the beginning of the name of dummy variables
# (i.e. not used).
dummy-variables-rgx=_|dummy
# List of additional names supposed to be defined in builtins. Remember that
# you should avoid to define new builtins when possible.
additional-builtins=
[IMPORTS]
# Deprecated modules which should not be used, separated by a comma
deprecated-modules=regsub,string,TERMIOS,Bastion,rexec
# Create a graph of every (i.e. internal and external) dependencies in the
# given file (report RP0402 must not be disabled)
import-graph=
# Create a graph of external dependencies in the given file (report RP0402 must
# not be disabled)
ext-import-graph=
# Create a graph of internal dependencies in the given file (report RP0402 must
# not be disabled)
int-import-graph=
[DESIGN]
# Maximum number of arguments for function / method
max-args=5
# Argument names that match this expression will be ignored. Default to name
# with leading underscore
ignored-argument-names=_.*
# Maximum number of locals for function / method body
max-locals=15
# Maximum number of return / yield for function / method body
max-returns=6
# Maximum number of branch for function / method body
max-branches=12
# Maximum number of statements in function / method body
max-statements=50
# Maximum number of parents for a class (see R0901).
max-parents=7
# Maximum number of attributes for a class (see R0902).
max-attributes=7
# Minimum number of public methods for a class (see R0903).
min-public-methods=2
# Maximum number of public methods for a class (see R0904).
max-public-methods=20
[CLASSES]
# List of method names used to declare (i.e. assign) instance attributes.
defining-attr-methods=__init__,__new__,setUp
# List of valid names for the first argument in a class method.
valid-classmethod-first-arg=cls
[EXCEPTIONS]
# Exceptions that will emit a warning when being caught. Defaults to
# "Exception"
overgeneral-exceptions=builtins.BaseException,builtins.Exception

View File

@ -0,0 +1,2 @@
pbr>=2.0.0
PyYAML>=3.10.0

View File

@ -0,0 +1,40 @@
[metadata]
name = k8sapp-power-metrics
summary = StarlingX sysinv extensions for power-metrics
long_description = file: README.rst
long_description_content_type = text/x-rst
license = Apache 2.0
author = StarlingX
author-email = starlingx-discuss@lists.starlingx.io
home-page = https://www.starlingx.io/
classifier =
Environment :: OpenStack
Intended Audience :: Information Technology
Intended Audience :: System Administrators
License :: OSI Approved :: Apache Software License
Operating System :: POSIX :: Linux
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.9
[files]
packages =
k8sapp_power_metrics
[global]
setup-hooks =
pbr.hooks.setup_hook
[entry_points]
systemconfig.helm_applications =
power-metrics = systemconfig.helm_plugins.power_metrics
systemconfig.helm_plugins.power_metrics =
001_cadvisor = k8sapp_power_metrics.helm.cadvisor:CadvisorHelm
002_telegraf = k8sapp_power_metrics.helm.telegraf:TelegrafHelm
systemconfig.app_lifecycle =
power-metrics = k8sapp_power_metrics.lifecycle.lifecycle_power_metrics:PowerMetricsAppLifecycleOperator
[bdist_wheel]
universal = 1

View File

@ -0,0 +1,12 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import setuptools
setuptools.setup(
setup_requires=['pbr>=2.0.0'],
pbr=True)

View File

@ -0,0 +1,20 @@
# The order of packages is significant, because pip processes them in the order
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
hacking>=1.1.0,<=2.0.0 # Apache-2.0
astroid
bandit<1.7.2;python_version>="3.0"
coverage>=3.6
fixtures>=3.0.0 # Apache-2.0/BSD
mock>=2.0.0 # BSD
python-subunit>=0.0.18
requests-mock>=0.6.0 # Apache-2.0
sphinx
oslosphinx
oslotest>=3.2.0 # Apache-2.0
stestr>=1.0.0 # Apache-2.0
testrepository>=0.0.18
testtools!=1.2.0,>=0.9.36
isort<5;python_version>="3.0"
pylint
pycryptodomex

View File

@ -0,0 +1,88 @@
[tox]
envlist = flake8,py39,pylint,bandit
minversion = 2.9
skipsdist = True
# tox does not work if the path to the workdir is too long, so move it to /tmp
toxworkdir = /tmp/{env:USER}_k8spowermetricstox
stxdir = {toxinidir}/../../..
distshare={toxworkdir}/.tox/distshare
[testenv]
allowlist_externals = bash
find
basepython = python3.9
sitepackages = False
install_command = pip install -v -v -v \
-c{toxinidir}/upper-constraints.txt \
-c{env:UPPER_CONSTRAINTS_FILE:https://opendev.org/starlingx/root/raw/branch/master/build-tools/requirements/debian/upper-constraints.txt} \
{opts} {packages}
# Note the hash seed is set to 0 until can be tested with a
# random hash seed successfully.
setenv = VIRTUAL_ENV={envdir}
PYTHONHASHSEED=0
PYTHONDONTWRITEBYTECODE=1
OS_TEST_PATH=./k8sapp_power_metrics/tests
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_ALL=C
SYSINV_TEST_ENV=True
TOX_WORK_DIR={toxworkdir}
PYLINTHOME={toxworkdir}
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
-e{[tox]stxdir}/config/sysinv/sysinv/sysinv
-e{[tox]stxdir}/config/tsconfig/tsconfig
-e{[tox]stxdir}/fault/fm-api/source
-e{[tox]stxdir}/fault/python-fmclient/fmclient
-e{[tox]stxdir}/utilities/ceph/python-cephclient/python-cephclient
-e{[tox]stxdir}/update/sw-patch/cgcs-patch
commands =
find . -type f -name "*.pyc" -delete
[flake8]
exclude = build,dist,tools,.eggs
max-line-length=80
[testenv:flake8]
deps = -r{toxinidir}/test-requirements.txt
commands =
flake8 {posargs} .
[testenv:py39]
commands =
{[testenv]commands}
stestr run {posargs}
stestr slowest
[testenv:pep8]
deps = {[testenv:flake8]deps}
commands = {[testenv:flake8]commands}
[testenv:venv]
commands = {posargs}
[bandit]
# Add bandit configuration here
[testenv:bandit]
deps = -r{toxinidir}/test-requirements.txt
commands = bandit --ini tox.ini -n 5 -r k8sapp_power_metrics
[testenv:pylint]
commands =
pylint {posargs} k8sapp_power_metrics --rcfile=./pylint.rc
[testenv:pip-missing-reqs]
# do not install test-requirements as that will pollute the virtualenv for
# determining missing packages
# this also means that pip-missing-reqs must be installed separately, outside
# of the requirements.txt files
deps = pip_missing_reqs
-rrequirements.txt
commands=pip-missing-reqs -d --ignore-file=/k8sapp_power_metrics/tests k8sapp_power_metrics

View File

@ -0,0 +1 @@
# Override upstream constraints based on StarlingX load

View File

@ -0,0 +1,5 @@
stx-power-metrics-helm (1.0-1) unstable; urgency=medium
* Initial release.
-- Fabio Studyny Higa <fabio.studynyhiga@windriver.com> Mon, 3 Jul 2023 13:30:15 +0000

View File

@ -0,0 +1,20 @@
Source: stx-power-metrics-helm
Section: libs
Priority: optional
Maintainer: StarlingX Developers <starlingx-discuss@lists.starlingx.io>
Build-Depends: debhelper-compat (= 13),
helm,
procps,
python3-k8sapp-power-metrics,
python3-k8sapp-power-metrics-wheels,
telegraf-helm,
Standards-Version: 4.5.1
Homepage: https://www.starlingx.io
Package: stx-power-metrics-helm
Section: libs
Architecture: any
Depends: ${misc:Depends}
Description: StarlingX Power Metrics FluxCD Helm Charts
This package contains FluxCD helm charts for the power metrics
application.

View File

@ -0,0 +1,41 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: stx-power-metrics-helm
Source: https://opendev.org/starlingx/app-power-metrics/
Files: *
Copyright: (c) 2023 Wind River Systems, Inc
License: Apache-2
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
.
https://www.apache.org/licenses/LICENSE-2.0
.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
.
On Debian-based systems the full text of the Apache version 2.0 license
can be found in `/usr/share/common-licenses/Apache-2.0'.
# If you want to use GPL v2 or later for the /debian/* files use
# the following clauses, or change it to suit. Delete these two lines
Files: debian/*
Copyright: 2023 Wind River Systems, Inc
License: Apache-2
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
.
https://www.apache.org/licenses/LICENSE-2.0
.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
.
On Debian-based systems the full text of the Apache version 2.0 license
can be found in `/usr/share/common-licenses/Apache-2.0'.

View File

@ -0,0 +1,58 @@
#!/usr/bin/make -f
# export DH_VERBOSE = 1
export ROOT = debian/tmp
export APP_FOLDER = $(ROOT)/usr/local/share/applications/helm
export DEB_VERSION = $(shell dpkg-parsechangelog | egrep '^Version:' | cut -f 2 -d ' ')
export RELEASE = $(shell echo $(DEB_VERSION) | cut -f 1 -d '-')
export REVISION = $(shell echo $(DEB_VERSION) | cut -f 4 -d '.')
export APP_NAME = power-metrics
export APP_VERSION = $(RELEASE)-$(REVISION)
export APP_TARBALL = $(APP_NAME)-$(APP_VERSION).tgz
export HELM_REPO = stx-platform
export HELM_FOLDER = /usr/lib/helm
export STAGING = staging
%:
dh $@
override_dh_auto_build:
# Create the TGZ file
cd helm-charts && $(MAKE)
# Setup the staging directory
mkdir -p $(STAGING)
cp files/metadata.yaml $(STAGING)
mkdir -p $(STAGING)/charts
cp $(HELM_FOLDER)/*.tgz $(STAGING)/charts
cp helm-charts/*.tgz $(STAGING)/charts
# Populate metadata
sed -i 's/@APP_NAME@/$(APP_NAME)/g' $(STAGING)/metadata.yaml
sed -i 's/@APP_VERSION@/$(APP_VERSION)/g' $(STAGING)/metadata.yaml
sed -i 's/@HELM_REPO@/$(HELM_REPO)/g' $(STAGING)/metadata.yaml
# Copy the plugins: installed in the buildroot
mkdir -p $(STAGING)/plugins
cp /plugins/*.whl $(STAGING)/plugins
# Prepare staging for fluxcd package
cp -R fluxcd-manifests $(STAGING)/
# Calculate checksum of all files in staging for the fluxcd app
cd $(STAGING) && find . -type f ! -name '*.md5' -print0 | xargs -0 md5sum > checksum.md5
# Package fluxcd app
tar cfz $(APP_TARBALL) -C $(STAGING)/ .
# Cleanup staging
rm -rf $(STAGING)
override_dh_auto_install:
# Install the app tar file.
install -d -m 755 $(APP_FOLDER)
install -p -D -m 755 $(APP_TARBALL) $(APP_FOLDER)
override_dh_usrlocal:

View File

@ -0,0 +1 @@
3.0 (quilt)

View File

@ -0,0 +1 @@
usr/local/share/applications/helm/*

View File

@ -0,0 +1,9 @@
---
debname: stx-power-metrics-helm
debver: 1.0-1
src_path: stx-power-metrics-helm
revision:
dist: $STX_DIST
GITREVCOUNT:
SRC_DIR: ${MY_REPO}/stx/app-power-metrics
BASE_SRCREV: 5304930dae1e62dbea8cdc59d756b2b1fcae76a5

View File

@ -0,0 +1,8 @@
maintain_user_overrides: true
app_name: @APP_NAME@
app_version: @APP_VERSION@
helm_repo: @HELM_REPO@
upgrades:
auto_update: true

View File

@ -0,0 +1,13 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
apiVersion: source.toolkit.fluxcd.io/v1beta1
kind: HelmRepository
metadata:
name: stx-platform
spec:
url: http://192.168.206.1:8080/helm_charts/stx-platform
interval: 1m

View File

@ -0,0 +1,8 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
resources:
- helmrepository.yaml

View File

@ -0,0 +1,10 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
apiVersion: v1
kind: Namespace
metadata:
name: power-metrics

View File

@ -0,0 +1,11 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
imagePullSecrets: default-registry-key
image:
digest: ""
repository: "docker.io/starlingx/cadvisor"
tag: "stx.9.0-v0.47.2"
pullPolicy: IfNotPresent

View File

@ -0,0 +1,5 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#

View File

@ -0,0 +1,36 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
apiVersion: "helm.toolkit.fluxcd.io/v2beta1"
kind: HelmRelease
metadata:
name: cadvisor
labels:
chart_group: cadvisor
spec:
releaseName: cadvisor
chart:
spec:
chart: cadvisor
version: 0.47.3
sourceRef:
kind: HelmRepository
name: stx-platform
interval: 1m
timeout: 30m
test:
enable: false
install:
disableHooks: false
upgrade:
disableHooks: false
valuesFrom:
- kind: Secret
name: cadvisor-static-overrides
valuesKey: cadvisor-static-overrides.yaml
- kind: Secret
name: cadvisor-system-overrides
valuesKey: cadvisor-system-overrides.yaml

View File

@ -0,0 +1,18 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
namespace: power-metrics
resources:
- helmrelease.yaml
secretGenerator:
- name: cadvisor-static-overrides
files:
- cadvisor-static-overrides.yaml
- name: cadvisor-system-overrides
files:
- cadvisor-system-overrides.yaml
generatorOptions:
disableNameSuffixHash: true

View File

@ -0,0 +1,13 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: power-metrics
resources:
- base
- cadvisor
- telegraf

View File

@ -0,0 +1,36 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
apiVersion: "helm.toolkit.fluxcd.io/v2beta1"
kind: HelmRelease
metadata:
name: telegraf
labels:
chart_group: telegraf
spec:
releaseName: telegraf
chart:
spec:
chart: telegraf
version: 1.1.12
sourceRef:
kind: HelmRepository
name: stx-platform
interval: 1m
timeout: 30m
test:
enable: false
install:
disableHooks: false
upgrade:
disableHooks: false
valuesFrom:
- kind: Secret
name: telegraf-static-overrides
valuesKey: telegraf-static-overrides.yaml
- kind: Secret
name: telegraf-system-overrides
valuesKey: telegraf-system-overrides.yaml

View File

@ -0,0 +1,18 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
namespace: power-metrics
resources:
- helmrelease.yaml
secretGenerator:
- name: telegraf-static-overrides
files:
- telegraf-static-overrides.yaml
- name: telegraf-system-overrides
files:
- telegraf-system-overrides.yaml
generatorOptions:
disableNameSuffixHash: true

View File

@ -0,0 +1,11 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
imagePullSecrets: default-registry-key
image:
digest: ""
repository: "docker.io/starlingx/telegraf"
tag: "stx.9.0-v1.27.3"
pullPolicy: IfNotPresent

View File

@ -0,0 +1,5 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#

View File

@ -0,0 +1,42 @@
#
# Copyright 2017 The Openstack-Helm Authors.
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# It's necessary to set this because some environments don't link sh -> bash.
SHELL := /bin/bash
TASK := build
EXCLUDES := doc tests tools logs tmp
CHARTS := $(filter-out $(EXCLUDES), $(patsubst %/.,%,$(wildcard */.)))
.PHONY: $(EXCLUDES) $(CHARTS)
all: $(CHARTS)
$(CHARTS):
@if [ -d $@ ]; then \
echo; \
echo "===== Processing [$@] chart ====="; \
$(MAKE) $(TASK)-$@; \
fi
init-%:
if [ -f $*/Makefile ]; then make -C $*; fi
lint-%: init-%
if [ -d $* ]; then helm lint $*; fi
build-%: lint-%
if [ -d $* ]; then helm package $*; fi
clean:
@echo "Clean all build artifacts"
rm -f */templates/_partials.tpl */templates/_globals.tpl
rm -f *tgz */charts/*tgz */requirements.lock
rm -rf */charts */tmpcharts
%:
@:

View File

@ -0,0 +1,10 @@
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
apiVersion: v2
appVersion: 0.47.3
description: A Helm chart for cAdvisor
name: cadvisor
type: application
version: 0.47.3

View File

@ -0,0 +1,32 @@
# cAdvisor Helm Chart
This Helm Chart comes with everything that is needed to run cAdvisor.
## Testing
This helm chart was validated using an image based on release 0.47.3 of
cadvisor, available at https://github.com/google/cadvisor/tree/v0.47.3.
## How to install
This chart can be installed using the default values with:
```console
$ helm upgrade --install cadvisor stx-platform/cadvisor
```
It is possible to replace the default "args" values of values.yaml file to
change or add new args to cAdvisor.
Please consult [cAdvisor Runtime Options](https://github.com/google/cadvisor/blob/master/docs/runtime_options.md)
for reference to what can be added.
If needed, it is also possible to add new volumes to be mounted overriding the
"volumes" column in the values.yaml file.
You may want to override values.yaml file use the following command:
```console
$ helm upgrade --install cadvisor -f values.yaml stx-platform/cadvisor
```
For more information about installing and using Helm, see the
[Helm Docs](https://helm.sh/docs/). For a quick introduction to Charts,
see the [Chart Guide](https://helm.sh/docs/topics/charts/).

View File

@ -0,0 +1,55 @@
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
{{/*
Expand the name of the chart.
*/}}
{{- define "cadvisor.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "cadvisor.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "cadvisor.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "cadvisor.labels" -}}
helm.sh/chart: {{ include "cadvisor.chart" . }}
{{ include "cadvisor.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "cadvisor.selectorLabels" -}}
app.kubernetes.io/name: {{ include "cadvisor.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

View File

@ -0,0 +1,30 @@
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
{{- if .Values.perf_events }}
apiVersion: v1
kind: ConfigMap
metadata:
name: cadvisor-perf-events
labels:
{{- include "cadvisor.labels" . | nindent 4 }}
data:
cadvisor_perf_events.json: |
{
"core": {
"events": [
"INST_RETIRED.ANY"
],
"custom_events": [
{
"config": [
"0xc0"
],
"name": "INST_RETIRED.ANY",
"type": 4
}
]
}
}
{{- end }}

View File

@ -0,0 +1,74 @@
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: {{ include "cadvisor.fullname" . }}
labels:
{{- include "cadvisor.labels" . | nindent 4 }}
spec:
selector:
matchLabels:
{{- include "cadvisor.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "cadvisor.selectorLabels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{ toYaml . | indent 8 }}
{{- end }}
spec:
automountServiceAccountToken: false
{{- with .Values.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
containers:
- image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
name: {{ .Chart.Name }}
args:
{{- if .Values.perf_events }}
{{ toYaml .Values.perf_args | indent 10 }}
{{- end }}
{{- with .Values.args }}
{{ toYaml . | indent 10 }}
{{- end }}
ports:
- containerPort: 8080
name: http
protocol: TCP
resources:
{{ toYaml .Values.resources | indent 10 }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
volumeMounts:
{{- if .Values.perf_events }}
- mountPath: /etc/cadvisor/cadvisor_perf_events.json
name: cadvisor-perf-events
subPath: cadvisor_perf_events.json
readOnly: true
{{- end }}
{{- range .Values.volumes }}
- mountPath: {{ default .path .mount }}
name: {{ .name }}
readOnly: true
{{- end }}
serviceAccountName: cadvisor
terminationGracePeriodSeconds: 30
volumes:
{{- if .Values.perf_events }}
- configMap:
name: cadvisor-perf-events
name: cadvisor-perf-events
{{- end }}
{{- range .Values.volumes }}
- hostPath:
path: {{ .path }}
name: {{ .name }}
{{- end }}

View File

@ -0,0 +1,20 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
apiVersion: v1
kind: Service
metadata:
name: {{ include "cadvisor.fullname" . }}
labels:
{{- include "cadvisor.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "cadvisor.selectorLabels" . | nindent 4 }}

View File

@ -0,0 +1,18 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
apiVersion: v1
kind: ServiceAccount
imagePullSecrets:
- name: "{{ .Values.imagePullSecrets }}"
metadata:
name: cadvisor
labels:
{{- include "cadvisor.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}

View File

@ -0,0 +1,72 @@
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# Default values for cadvisor.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
image:
repository: docker.io/starlingx/cadvisor
tag: stx.9.0-v0.47.2
pullPolicy: IfNotPresent
imagePullSecrets: default-registry-key
nameOverride: ""
fullnameOverride: ""
serviceAccount:
annotations: {}
podAnnotations: {}
podSecurityContext: {}
securityContext:
privileged: true
service:
type: ClusterIP
port: 80
resources:
limits:
cpu: 800m
memory: 2000Mi
requests:
cpu: 0
memory: 400Mi
nodeSelector:
power-metrics: "enabled"
tolerations: []
affinity: {}
perf_events: true
perf_args:
- --perf_events_config=/etc/cadvisor/cadvisor_perf_events.json
args:
- --v=0
- --raw_cgroup_prefix_whitelist=k8s-infra
- --store_container_labels=false
- --whitelisted_container_labels=io.kubernetes.container.name,io.kubernetes.pod.name,io.kubernetes.pod.namespace,io.kubernetes.pod.uid
- --disable_metrics=cpu_topology,disk,diskIO,memory_numa,network,tcp,udp,sched,process,hugetlb,referenced_memory,resctrl,cpuset,advtcp
volumes:
- name: rootfs
path: "/"
mount: "/rootfs"
- name: var-run
path: "/var/run"
- name: sys
path: "/sys"
- name: docker
path: "/var/lib/docker"
- name: disk
path: "/dev/disk"

View File

@ -0,0 +1,54 @@
#!/bin/sh
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
IMAGE=$1
IMAGE_TAG=$2
echo "=============== build script ================"
echo image: "${IMAGE}"
echo image_tag: "${IMAGE_TAG}"
pwd
if [ -z "${IMAGE_TAG}" ]; then
echo "Image tag must be specified. build ${IMAGE} Aborting..." >&2
exit 1
fi
build_cadvisor_image() {
export CADVISOR_IMAGE=$1
echo "cadvisor_image: ${CADVISOR_IMAGE}"
pwd
docker build -t "${CADVISOR_IMAGE}" -f deploy/Dockerfile .
echo "cadvisor image build done"
return 0
}
build_telegraf_image() {
export TELEGRAF_IMAGE=$1
echo "telegraf_image: ${TELEGRAF_IMAGE}"
pwd
docker build -t "${TELEGRAF_IMAGE}" -f Dockerfile .
echo "telegraf image build done"
return 0
}
case ${IMAGE} in
cadvisor)
echo "Build image: cadvisor"
build_cadvisor_image "${IMAGE_TAG}"
;;
telegraf)
echo "build image: telegraf"
build_telegraf_image "${IMAGE_TAG}"
;;
*)
echo "Unsupported ARGS in ${0}: ${IMAGE}" >&2
exit 1
;;
esac
exit 0

View File

@ -0,0 +1,8 @@
BUILDER=script
LABEL=cadvisor
SOURCE_REPO=https://github.com/google/cadvisor.git
SOURCE_REF=v0.47.3
SOURCE_PATCHES="../files/cadvisor-0001-Fix-flags-typo.patch"
COMMAND=bash
SCRIPT=build.sh
ARGS=cadvisor

View File

@ -0,0 +1,8 @@
BUILDER=script
LABEL=telegraf
SOURCE_REPO=https://github.com/influxdata/telegraf.git
SOURCE_REF=v1.27.3
SOURCE_PATCHES="../files/telegraf-0001-Patch-for-docker-image.patch ../files/telegraf-0002-fix-inputs.intel_powerstat-reduce-msr-read-latency-o.patch ../files/telegraf-0003-feat-intel.powerstat-Estimate-isolated-core-frequenc.patch"
COMMAND=bash
SCRIPT=build.sh
ARGS=telegraf

View File

@ -0,0 +1,46 @@
From 0206b1abbb215ebd948f151e95b20befb11db3db Mon Sep 17 00:00:00 2001
From: Caio Cesar Ferreira <Caio.CesarFerreira@windriver.com>
Date: Wed, 14 Jun 2023 09:58:18 -0300
Subject: [PATCH] Fix flags typo
Fix typo in GO_TAGS variable in Dockerfile. This typo was preventing cadvisor to
compile with libpfm support.
This fix is already on upstream and will be available on next release:
https://github.com/google/cadvisor/commit/0206b1abbb215ebd948f151e95b20befb11db3db
Signed-off-by: Caio Cesar Ferreira <Caio.CesarFerreira@windriver.com>
---
build/build.sh | 2 +-
deploy/Dockerfile | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/build/build.sh b/build/build.sh
index 05332b14..e0613553 100755
--- a/build/build.sh
+++ b/build/build.sh
@@ -19,7 +19,7 @@ set -e
export GOOS=${GOOS:-$(go env GOOS)}
export GOARCH=${GOARCH:-$(go env GOARCH)}
export CGO_ENABLED=${GO_CGO_ENABLED:-"1"}
-GO_FLAGS=${GO_FLAGS:-"-tags netgo"} # Extra go flags to use in the build.
+GO_FLAGS=${GO_FLAGS:-"-tags=netgo"} # Extra go flags to use in the build.
BUILD_USER=${BUILD_USER:-"${USER}@${HOSTNAME}"}
BUILD_DATE=${BUILD_DATE:-$( date +%Y%m%d-%H:%M:%S )}
VERBOSE=${VERBOSE:-}
diff --git a/deploy/Dockerfile b/deploy/Dockerfile
index 6b533ebc..0bd5b7de 100644
--- a/deploy/Dockerfile
+++ b/deploy/Dockerfile
@@ -40,7 +40,7 @@ ADD . .
ARG VERSION
# libipmctl only works on x86_64 CPUs.
-RUN export GO_TAGS="-tags=libfpm,netgo"; \
+RUN export GO_TAGS="libpfm,netgo"; \
if [ "$(uname --machine)" = "x86_64" ]; then \
export GO_TAGS="$GO_TAGS,libipmctl"; \
fi; \
--
2.25.1

View File

@ -0,0 +1,61 @@
From 9b0c5b4390949aec9574514b7f7952616fd204b7 Mon Sep 17 00:00:00 2001
From: Alyson Deives Pereira <alyson.deivespereira@windriver.com>
Date: Tue, 11 Jul 2023 13:19:26 -0300
Subject: [PATCH 1/3] Patch for docker image
The telegraf docker images are maintained in another repository [1].
Since we need to patch both telegraf source code and docker image,
we include the patched docker image into telegraf source code.
This patch customize the docker image with:
- ipmi-tool, required by ipmi-sensor plugin [2]
- runs telegraf as root instead of telegraf user, which is required by
Intel Powerstat plugin to read model specific registers (MSRs) to
retrieve data for calculation of per-CPU specific metrics [3]
[1] https://github.com/influxdata/influxdata-docker/tree/master/telegraf
[2] https://github.com/influxdata/telegraf/tree/master/plugins/inputs/ipmi_sensor
[3] https://github.com/influxdata/telegraf/tree/master/plugins/inputs/intel_powerstat
Signed-off-by: Alyson Deives Pereira <alyson.deivespereira@windriver.com>
---
Dockerfile | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
create mode 100644 Dockerfile
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 000000000..61bd1919e
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,27 @@
+FROM golang:1.20 AS build
+
+WORKDIR /go/src/github.com/influxdata/telegraf
+RUN git config --global --add safe.directory .
+
+# Cache Golang Dependencies for faster incremental builds
+ADD go.mod go.sum ./
+RUN go mod download
+
+ADD . .
+RUN make config
+RUN make linux_amd64.tar.gz
+
+FROM alpine:3.17
+
+RUN apk update && \
+ apk add --update --no-cache \
+ ipmitool=~1.8 && \
+ rm -rf /var/lib/apt/lists/*
+
+ENV BUILD_DIR /go/src/github.com/influxdata/telegraf/build/linux-amd64-tar/telegraf-*
+
+COPY --from=build $BUILD_DIR/etc /etc
+COPY --from=build $BUILD_DIR/usr /usr
+COPY --from=build $BUILD_DIR/var /var
+
+ENTRYPOINT ["/usr/bin/telegraf"]
--
2.25.1

View File

@ -0,0 +1,236 @@
From 05d41aed1c5769b4ab2d7c79a5549548533c6cff Mon Sep 17 00:00:00 2001
From: Alyson Deives Pereira <alyson.deivespereira@windriver.com>
Date: Mon, 19 Jun 2023 11:27:51 -0300
Subject: [PATCH 2/3] fix(inputs.intel_powerstat): reduce msr read latency on
preempt-rt kernels
Using cyclictest utility from rt-tests [1] results on latency increase
when telegraf is executed on a preempt-rt kernel with isolated cores.
This increase occurs because of the concurrent read of MSR with goroutines.
To fix this issue, the read_method parameter was added.
This parameter accepts two values, concurrent or sequential.
Concurrent method is the current behavior using goroutines to read
each MSR value concurrently.
The sequential method reads each value sequentially. This reduces latency
overhead, but might cause loss of precision on metrics calculation.
NOTE: This issue was reported on upstream:
https://github.com/influxdata/telegraf/issues/13828
[1] https://git.kernel.org/pub/scm/utils/rt-tests/rt-tests.git
Signed-off-by: Alyson Deives Pereira <alyson.deivespereira@windriver.com>
---
.../inputs/intel_powerstat/intel_powerstat.go | 12 ++-
plugins/inputs/intel_powerstat/msr.go | 91 +++++++++++++++----
plugins/inputs/intel_powerstat/msr_test.go | 3 +-
3 files changed, 88 insertions(+), 18 deletions(-)
diff --git a/plugins/inputs/intel_powerstat/intel_powerstat.go b/plugins/inputs/intel_powerstat/intel_powerstat.go
index 25cdd96b7..e05f8a642 100644
--- a/plugins/inputs/intel_powerstat/intel_powerstat.go
+++ b/plugins/inputs/intel_powerstat/intel_powerstat.go
@@ -37,10 +37,15 @@ const (
percentageMultiplier = 100
)
+var (
+ knownReadMethods = []string{"concurrent", "sequential"}
+)
+
// PowerStat plugin enables monitoring of platform metrics (power, TDP) and Core metrics like temperature, power and utilization.
type PowerStat struct {
CPUMetrics []string `toml:"cpu_metrics"`
PackageMetrics []string `toml:"package_metrics"`
+ ReadMethod string `toml:"read_method"`
Log telegraf.Logger `toml:"-"`
fs fileService
@@ -81,6 +86,10 @@ func (p *PowerStat) Init() error {
return err
}
+ if !contains(knownReadMethods, p.ReadMethod) {
+ return fmt.Errorf("provided read method %q is not valid", p.ReadMethod)
+ }
+
p.initMSR()
p.initRaplService()
@@ -96,7 +105,7 @@ func (p *PowerStat) initMSR() {
// Initialize MSR service only when there is at least one metric enabled
if p.cpuFrequency || p.cpuBusyFrequency || p.cpuTemperature || p.cpuC0StateResidency || p.cpuC1StateResidency ||
p.cpuC6StateResidency || p.cpuBusyCycles || p.packageTurboLimit || p.packageUncoreFrequency || p.packageCPUBaseFrequency {
- p.msr = newMsrServiceWithFs(p.Log, p.fs)
+ p.msr = newMsrServiceWithFs(p.Log, p.fs, p.ReadMethod)
}
}
@@ -903,6 +912,7 @@ func newPowerStat(fs fileService) *PowerStat {
skipFirstIteration: true,
fs: fs,
logOnce: make(map[string]error),
+ ReadMethod: "concurrent",
}
return p
diff --git a/plugins/inputs/intel_powerstat/msr.go b/plugins/inputs/intel_powerstat/msr.go
index 52690c4a1..2b5902f2c 100644
--- a/plugins/inputs/intel_powerstat/msr.go
+++ b/plugins/inputs/intel_powerstat/msr.go
@@ -62,6 +62,7 @@ type msrServiceImpl struct {
msrOffsets []int64
fs fileService
log telegraf.Logger
+ readMethod string
}
func (m *msrServiceImpl) getCPUCoresData() map[string]*msrData {
@@ -195,11 +196,39 @@ func (m *msrServiceImpl) readSingleMsr(core string, msr string) (uint64, error)
return value, nil
}
-func (m *msrServiceImpl) readDataFromMsr(core string, reader io.ReaderAt) error {
- g, ctx := errgroup.WithContext(context.Background())
+func (m *msrServiceImpl) sequentialMSRRead(reader io.ReaderAt) (msrData, error) {
+ // Create and populate a map that contains msr offsets along with their respective values
+ msrOffsets := make(map[int64]uint64)
+ var data msrData
+
+ for _, offset := range m.msrOffsets {
+ value, err := m.fs.readFileAtOffsetToUint64(reader, offset)
+ if err != nil {
+ return data, fmt.Errorf("error reading MSR value %x: %w", offset, err)
+ }
+ msrOffsets[offset] = value
+ }
+ throttleTemp := msrOffsets[throttleTemperatureLocation]
+ temp := msrOffsets[temperatureLocation]
+
+ data.c3 = msrOffsets[c3StateResidencyLocation]
+ data.c6 = msrOffsets[c6StateResidencyLocation]
+ data.c7 = msrOffsets[c7StateResidencyLocation]
+ data.mperf = msrOffsets[maximumFrequencyClockCountLocation]
+ data.aperf = msrOffsets[actualFrequencyClockCountLocation]
+ data.timeStampCounter = msrOffsets[timestampCounterLocation]
+ data.throttleTemp = int64((throttleTemp >> 16) & 0xFF)
+ data.temp = int64((temp >> 16) & 0xFF)
+
+ return data, nil
+}
+
+func (m *msrServiceImpl) concurrentMSRRead(reader io.ReaderAt) (msrData, error) {
+ g, ctx := errgroup.WithContext(context.Background())
// Create and populate a map that contains msr offsets along with their respective channels
msrOffsetsWithChannels := make(map[int64]chan uint64)
+ var data msrData
for _, offset := range m.msrOffsets {
msrOffsetsWithChannels[offset] = make(chan uint64)
}
@@ -221,19 +250,48 @@ func (m *msrServiceImpl) readDataFromMsr(core string, reader io.ReaderAt) error
}(offset, channel)
}
- newC3 := <-msrOffsetsWithChannels[c3StateResidencyLocation]
- newC6 := <-msrOffsetsWithChannels[c6StateResidencyLocation]
- newC7 := <-msrOffsetsWithChannels[c7StateResidencyLocation]
- newMperf := <-msrOffsetsWithChannels[maximumFrequencyClockCountLocation]
- newAperf := <-msrOffsetsWithChannels[actualFrequencyClockCountLocation]
- newTsc := <-msrOffsetsWithChannels[timestampCounterLocation]
- newThrottleTemp := <-msrOffsetsWithChannels[throttleTemperatureLocation]
- newTemp := <-msrOffsetsWithChannels[temperatureLocation]
+ throttleTemp := <-msrOffsetsWithChannels[throttleTemperatureLocation]
+ temp := <-msrOffsetsWithChannels[temperatureLocation]
+
+ data.c3 = <-msrOffsetsWithChannels[c3StateResidencyLocation]
+ data.c6 = <-msrOffsetsWithChannels[c6StateResidencyLocation]
+ data.c7 = <-msrOffsetsWithChannels[c7StateResidencyLocation]
+ data.mperf = <-msrOffsetsWithChannels[maximumFrequencyClockCountLocation]
+ data.aperf = <-msrOffsetsWithChannels[actualFrequencyClockCountLocation]
+ data.timeStampCounter = <-msrOffsetsWithChannels[timestampCounterLocation]
+ data.throttleTemp = int64((throttleTemp >> 16) & 0xFF)
+ data.temp = int64((temp >> 16) & 0xFF)
if err := g.Wait(); err != nil {
- return fmt.Errorf("received error during reading MSR values in goroutines: %w", err)
+ return data, fmt.Errorf("received error during reading MSR values in goroutines: %w", err)
+ }
+
+ return data, nil
+}
+
+func (m *msrServiceImpl) readDataFromMsr(core string, reader io.ReaderAt) error {
+ var data msrData
+ var err error
+ switch m.readMethod {
+ case "concurrent":
+ data, err = m.concurrentMSRRead(reader)
+ case "sequential":
+ data, err = m.sequentialMSRRead(reader)
}
+ if err != nil {
+ return err
+ }
+
+ newC3 := data.c3
+ newC6 := data.c6
+ newC7 := data.c7
+ newMperf := data.mperf
+ newAperf := data.aperf
+ newTsc := data.timeStampCounter
+ newThrottleTemp := data.throttleTemp
+ newTemp := data.temp
+
m.cpuCoresData[core].c3Delta = newC3 - m.cpuCoresData[core].c3
m.cpuCoresData[core].c6Delta = newC6 - m.cpuCoresData[core].c6
m.cpuCoresData[core].c7Delta = newC7 - m.cpuCoresData[core].c7
@@ -248,9 +306,9 @@ func (m *msrServiceImpl) readDataFromMsr(core string, reader io.ReaderAt) error
m.cpuCoresData[core].aperf = newAperf
m.cpuCoresData[core].timeStampCounter = newTsc
// MSR (1A2h) IA32_TEMPERATURE_TARGET bits 23:16.
- m.cpuCoresData[core].throttleTemp = int64((newThrottleTemp >> 16) & 0xFF)
+ m.cpuCoresData[core].throttleTemp = newThrottleTemp
// MSR (19Ch) IA32_THERM_STATUS bits 22:16.
- m.cpuCoresData[core].temp = int64((newTemp >> 16) & 0x7F)
+ m.cpuCoresData[core].temp = newTemp
return nil
}
@@ -309,10 +367,11 @@ func (m *msrServiceImpl) setCPUCores() error {
return nil
}
-func newMsrServiceWithFs(logger telegraf.Logger, fs fileService) *msrServiceImpl {
+func newMsrServiceWithFs(logger telegraf.Logger, fs fileService, readMethod string) *msrServiceImpl {
msrService := &msrServiceImpl{
- fs: fs,
- log: logger,
+ fs: fs,
+ log: logger,
+ readMethod: readMethod,
}
err := msrService.setCPUCores()
if err != nil {
diff --git a/plugins/inputs/intel_powerstat/msr_test.go b/plugins/inputs/intel_powerstat/msr_test.go
index 5090d10a6..708297a90 100644
--- a/plugins/inputs/intel_powerstat/msr_test.go
+++ b/plugins/inputs/intel_powerstat/msr_test.go
@@ -179,10 +179,11 @@ func verifyCPUCoresData(cores []string, t *testing.T, msr *msrServiceImpl, expec
func getMsrServiceWithMockedFs() (*msrServiceImpl, *mockFileService) {
cores := []string{"cpu0", "cpu1", "cpu2", "cpu3"}
logger := testutil.Logger{Name: "PowerPluginTest"}
+ readMethod := "concurrent"
fsMock := &mockFileService{}
fsMock.On("getStringsMatchingPatternOnPath", mock.Anything).
Return(cores, nil).Once()
- msr := newMsrServiceWithFs(logger, fsMock)
+ msr := newMsrServiceWithFs(logger, fsMock, readMethod)
return msr, fsMock
}
--
2.25.1

View File

@ -0,0 +1,123 @@
From 0ff7a3f8ff5c47f6bbea18f6ba4e6d981a8836de Mon Sep 17 00:00:00 2001
From: Alyson Deives Pereira <alyson.deivespereira@windriver.com>
Date: Fri, 11 Aug 2023 15:16:51 -0300
Subject: [PATCH 3/3] feat(inputs.intel_powerstat): Estimate isolated core
frequency when intel_pstate is enabled
There is an issue with intel_pstate where cur_freq is not available
when nohz_full is enabled (i.e. the core is isolated).
To overcome this issue, we provide a naive core frequency estimation
according to intel_pstate governor. If the governor is powersave, we
use the core minimum scaling frequency, otherwise we use the maximum
scaling frequency.
NOTE: This issue was reported on upstream:
https://github.com/influxdata/telegraf/issues/13830
Signed-off-by: Alyson Deives Pereira <alyson.deivespereira@windriver.com>
---
plugins/inputs/intel_powerstat/msr.go | 70 +++++++++++++++++++++++++--
1 file changed, 67 insertions(+), 3 deletions(-)
diff --git a/plugins/inputs/intel_powerstat/msr.go b/plugins/inputs/intel_powerstat/msr.go
index 2b5902f2c..ffbe0ee78 100644
--- a/plugins/inputs/intel_powerstat/msr.go
+++ b/plugins/inputs/intel_powerstat/msr.go
@@ -18,6 +18,10 @@ import (
const (
systemCPUPath = "/sys/devices/system/cpu/"
cpuCurrentFreqPartialPath = "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_cur_freq"
+ cpuMinFreqPartialPath = "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_min_freq"
+ cpuMaxFreqPartialPath = "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_max_freq"
+ cpuDriverFreqPartialPath = "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_driver"
+ cpuGovernorFreqPartialPath = "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_governor"
msrPartialPath = "/dev/cpu/%s/msr"
uncoreFreqPath = "/sys/devices/system/cpu/intel_uncore_frequency/package_%s_die_%s/%s%s_freq_khz"
c3StateResidencyLocation = 0x3FC
@@ -78,19 +82,79 @@ func (m *msrServiceImpl) isMsrLoaded() bool {
}
return false
}
-func (m *msrServiceImpl) retrieveCPUFrequencyForCore(core string) (float64, error) {
- cpuFreqPath := fmt.Sprintf(cpuCurrentFreqPartialPath, core)
+
+func (m *msrServiceImpl) retrieveCPUFrequency(partialPath string, core string) (float64, error) {
+ cpuFreqPath := fmt.Sprintf(partialPath, core)
err := checkFile(cpuFreqPath)
if err != nil {
return 0, err
}
cpuFreqFile, err := os.Open(cpuFreqPath)
if err != nil {
- return 0, fmt.Errorf("error opening scaling_cur_freq file on path %q: %w", cpuFreqPath, err)
+ return 0, fmt.Errorf("error opening file on path %q: %w", cpuFreqPath, err)
}
defer cpuFreqFile.Close()
cpuFreq, _, err := m.fs.readFileToFloat64(cpuFreqFile)
+ return cpuFreq, err
+}
+
+func (m *msrServiceImpl) isUsingIntelPstateDriver(core string) (bool, error) {
+ driverFreqPath := fmt.Sprintf(cpuDriverFreqPartialPath, core)
+ err := checkFile(driverFreqPath)
+ if err != nil {
+ m.log.Errorf("error checking file on path %q: %w", driverFreqPath, err)
+ return false, err
+ }
+ driver, err := m.fs.readFile(driverFreqPath)
+ if err != nil {
+ return false, err
+ }
+ // Remove new line character
+ driverStr := strings.TrimRight(string(driver), "\n")
+
+ if driverStr == "intel_pstate" {
+ return true, nil
+ }
+ return false, nil
+}
+
+func (m *msrServiceImpl) retrieveCPUFrequencyGovernor(core string) (string, error) {
+ governorFreqPath := fmt.Sprintf(cpuGovernorFreqPartialPath, core)
+ err := checkFile(governorFreqPath)
+ if err != nil {
+ return "", err
+ }
+ governor, err := m.fs.readFile(governorFreqPath)
+ if err != nil {
+ return "", err
+ }
+ // Remove new line character
+ governorStr := strings.TrimRight(string(governor), "\n")
+ return governorStr, nil
+}
+
+func (m *msrServiceImpl) retrieveCPUFrequencyForCore(core string) (float64, error) {
+ cpuFreq, err := m.retrieveCPUFrequency(cpuCurrentFreqPartialPath, core)
+ // If intel_pstate is enabled, a frequency of 0 means that the core is isolated and/or with nohz_full enabled
+ // We estimate the core frequency according to scaling governor powersave or performance
+ if cpuFreq == 0 {
+ intelPstateDriver, err := m.isUsingIntelPstateDriver(core)
+ if err != nil {
+ return 0, err
+ }
+ if intelPstateDriver {
+ governor, err := m.retrieveCPUFrequencyGovernor(core)
+ if err != nil {
+ return 0, err
+ }
+ if governor == "powersave" {
+ cpuFreq, err = m.retrieveCPUFrequency(cpuMinFreqPartialPath, core)
+ } else {
+ cpuFreq, err = m.retrieveCPUFrequency(cpuMaxFreqPartialPath, core)
+ }
+ }
+ }
return convertKiloHertzToMegaHertz(cpuFreq), err
}
--
2.25.1

View File

@ -0,0 +1,5 @@
telegraf-helm (1.1-12) unstable; urgency=medium
* Initial release.
-- Alyson Deives Pereira <alyson.deivespereira@windriver.com> Tue, 22 Aug 2023 15:15:00 +0000

View File

@ -0,0 +1,15 @@
Source: telegraf-helm
Section: libs
Priority: optional
Maintainer: StarlingX Developers <starlingx-discuss@lists.starlingx.io>
Build-Depends: debhelper-compat (= 13),
helm
Standards-Version: 4.5.1
Homepage: https://www.starlingx.io
Package: telegraf-helm
Section: libs
Architecture: any
Depends: ${misc:Depends}
Description: StarlingX Telegraf Helm Charts
This package contains helm charts for Telegraf.

View File

@ -0,0 +1,41 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: telegraf-helm
Source: https://opendev.org/starlingx/app-power-metrics/
Files: *
Copyright: (c) 2023 Wind River Systems, Inc
License: Apache-2
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
.
https://www.apache.org/licenses/LICENSE-2.0
.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
.
On Debian-based systems the full text of the Apache version 2.0 license
can be found in `/usr/share/common-licenses/Apache-2.0'.
# If you want to use GPL v2 or later for the /debian/* files use
# the following clauses, or change it to suit. Delete these two lines
Files: debian/*
Copyright: 2022 Wind River Systems, Inc
License: Apache-2
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
.
https://www.apache.org/licenses/LICENSE-2.0
.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
.
On Debian-based systems the full text of the Apache version 2.0 license
can be found in `/usr/share/common-licenses/Apache-2.0'.

View File

@ -0,0 +1,689 @@
From e87754eea0d6c7fa72bd97a14067b918e8c22ccf Mon Sep 17 00:00:00 2001
From: Alyson Deives Pereira <alyson.deivespereira@windriver.com>
Date: Thu, 24 Aug 2023 17:35:42 -0300
Subject: [PATCH] Patch telegraf helm chart
The following changes are required for telegraf to provide power metrics:
- Change chart name from telegraf-ds to telegraf (for simplification)
- Change default image and tag to starlingx custom image
- Add imagePullSecrets to allow downloading images from registry.local
- Only enable the following input plugins by default:
- cpu, linux_cpu, ipmi_sensor, intel_powerstat and mem
- Add intel_pmu plugin (enabled by setting pmu_enabled to true)
- Change default output plugin from influxdb to prometheus_client
- Do not create RBAC resources by default
- Set dnsPolicy to ClusterFirstWithHostNet
- Add power-metrics nodeSelector
- Add securityContext and sets privileged=true
- Add ClusterIP for metrics output endpoint at port 9273
- Change cpu resource requests from 0.1 to 0
- Sets telegraf env vars HOST_ETC, HOST_RUN, and HOST_VAR
- Mount /lib/modules and /sys/kernel/debug directories
Signed-off-by: Alyson Deives Pereira <alyson.deivespereira@windriver.com>
Co-authored-by: Caio Cesar Ferreira <caio.cesarferreira@windriver.com>
---
charts/telegraf-ds/Chart.yaml | 2 +-
charts/telegraf-ds/README.md | 41 ++--
charts/telegraf-ds/templates/_helpers.tpl | 185 ++++++++++++++++++
charts/telegraf-ds/templates/configmap.yaml | 31 +--
charts/telegraf-ds/templates/daemonset.yaml | 26 ++-
.../templates/events_definition.yaml | 36 ++++
charts/telegraf-ds/templates/service.yaml | 14 ++
.../telegraf-ds/templates/serviceaccount.yaml | 2 +
charts/telegraf-ds/values.yaml | 107 +++++++---
9 files changed, 370 insertions(+), 74 deletions(-)
create mode 100644 charts/telegraf-ds/templates/events_definition.yaml
create mode 100644 charts/telegraf-ds/templates/service.yaml
diff --git a/charts/telegraf-ds/Chart.yaml b/charts/telegraf-ds/Chart.yaml
index eb67664..b7fcd09 100644
--- a/charts/telegraf-ds/Chart.yaml
+++ b/charts/telegraf-ds/Chart.yaml
@@ -1,5 +1,5 @@
apiVersion: v1
-name: telegraf-ds
+name: telegraf
version: 1.1.12
appVersion: 1.27.3
deprecated: false
diff --git a/charts/telegraf-ds/README.md b/charts/telegraf-ds/README.md
index 5c9fbc2..9037c95 100644
--- a/charts/telegraf-ds/README.md
+++ b/charts/telegraf-ds/README.md
@@ -12,18 +12,15 @@ The Telegraf-DS Helm chart uses the [Helm](https://helm.sh) package manager to b
## QuickStart
```console
-helm repo add influxdata https://helm.influxdata.com/
-helm upgrade --install telegraf-ds influxdata/telegraf-ds
+helm upgrade --install telegraf stx-platform/telegraf
```
-> **Tip**: `helm upgrade --install [RELEASE] [CHART] [FLAGS]` is idempotent and can be run multiple times. If chart hasn't been installed, Helm installs it. If chart is installed, Helm redeploys the same version or upgrades the chart if a new version is available.
-
## Install the chart
To install the chart with the release name `my-release`:
```console
-helm upgrade --install my-release influxdata/telegraf-ds
+helm upgrade --install my-release stx-platform/telegraf
```
The command deploys a Telegraf DaemonSet on the Kubernetes cluster in the default configuration. The [configuration](#configuration) section as well as the [values.yaml](/values.yaml) file lists the parameters that can be configured during installation.
@@ -46,37 +43,39 @@ The default configuration parameters are listed in `values.yaml`. To change the
```console
helm upgrade --install my-release \
- --set outputs.influxdb.urls=["http://foo.bar:8086"] \
- influxdata/telegraf-ds
+ --set config.linux_cpu.metrics=["cpufreq", "thermal"] \
+ stx-platform/telegraf
```
-This command lets the chart deploy by setting the InfluxDB URL for Telegraf to write to.
+This command lets the chart deploy by setting the Linux CPU metrics for Telegraf to report.
Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example,
```console
-helm upgrade --install my-release -f values.yaml influxdata/telegraf-ds
+helm upgrade --install my-release -f values.yaml stx-platform/telegraf
```
> **Tip**: `helm upgrade --install [RELEASE] [CHART] [FLAGS]` can be shortened : `helm upgrade -i [RELEASE] [CHART] [FLAGS]`
## Telegraf configuration
-This chart deploys the following by default:
+This chart deploys the following input plugins by default:
-- `telegraf` running as a DaemonSet (`telegraf-ds`) with the following plugins enabled
+- `telegraf` running as a DaemonSet with the following plugins enabled:
* [`cpu`](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/cpu)
- * [`disk`](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/disk)
- * [`diskio`](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/diskio)
- * [`docker`](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/docker)
- * [`kernel`](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/kernel)
- * [`kubernetes`](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/kubernetes)
+ * [`intel_powerstat`](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/intel_powerstat)
+ * [`ipmi_sensor`](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/ipmi_sensor)
+ * [`linux_cpu`](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/linux_cpu)
* [`mem`](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/mem)
- * [`net`](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/net)
- * [`processes`](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/processes)
- * [`swap`](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/swap)
- * [`system`](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/system)
-The following plugin can be enable through the configuration:
+The following plugin can be enabled through configuration:
+- [`docker`](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/docker)
+- [`intel_pmu`](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/intel_pmu)
- [`internal`](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/internal)
+
+Additional plugins can be enabled by overriding `config.inputs` parameter from `values.yaml`
+
+The following output plugin is used by default:
+ * [`prometheus_client`](https://github.com/influxdata/telegraf/tree/master/plugins/outputs/prometheus_client)
+
diff --git a/charts/telegraf-ds/templates/_helpers.tpl b/charts/telegraf-ds/templates/_helpers.tpl
index 331bdc5..35a2070 100644
--- a/charts/telegraf-ds/templates/_helpers.tpl
+++ b/charts/telegraf-ds/templates/_helpers.tpl
@@ -413,3 +413,188 @@ Activate inputs.internal through flag monitor_self
[[inputs.internal]]
{{- end }}
{{- end -}}
+
+{{- define "inputs" -}}
+{{- range $inputIdx, $configObject := . -}}
+ {{- range $input, $config := . -}}
+
+ [[inputs.{{- $input }}]]
+ {{- if $config -}}
+ {{- $tp := typeOf $config -}}
+ {{- if eq $tp "map[string]interface {}" -}}
+ {{- range $key, $value := $config -}}
+ {{- $tp := typeOf $value -}}
+ {{- if eq $tp "string" }}
+ {{ $key }} = {{ $value | quote }}
+ {{- end }}
+ {{- if eq $tp "float64" }}
+ {{ $key }} = {{ $value | int64 }}
+ {{- end }}
+ {{- if eq $tp "int" }}
+ {{ $key }} = {{ $value | int64 }}
+ {{- end }}
+ {{- if eq $tp "bool" }}
+ {{ $key }} = {{ $value }}
+ {{- end }}
+ {{- if eq $tp "[]interface {}" }}
+ {{ $key }} = [
+ {{- $numOut := len $value }}
+ {{- $numOut := sub $numOut 1 }}
+ {{- range $b, $val := $value }}
+ {{- $i := int64 $b }}
+ {{- $tp := typeOf $val }}
+ {{- if eq $i $numOut }}
+ {{- if eq $tp "string" }}
+ {{ $val | quote }}
+ {{- end }}
+ {{- if eq $tp "float64" }}
+ {{ $val | int64 }}
+ {{- end }}
+ {{- else }}
+ {{- if eq $tp "string" }}
+ {{ $val | quote }},
+ {{- end}}
+ {{- if eq $tp "float64" }}
+ {{ $val | int64 }},
+ {{- end }}
+ {{- end }}
+ {{- end }}
+ ]
+ {{- end }}
+ {{- end }}
+ {{- range $key, $value := $config -}}
+ {{- $tp := typeOf $value -}}
+ {{- if eq $tp "map[string]interface {}" }}
+ [[inputs.{{ $input }}.{{ $key }}]]
+ {{- range $k, $v := $value }}
+ {{- $tps := typeOf $v }}
+ {{- if eq $tps "string" }}
+ {{ $k }} = {{ $v | quote }}
+ {{- end }}
+ {{- if eq $tps "float64" }}
+ {{ $k }} = {{ $v | int64 }}.0
+ {{- end }}
+ {{- if eq $tps "int64" }}
+ {{ $k }} = {{ $v | int64 }}
+ {{- end }}
+ {{- if eq $tps "bool" }}
+ {{ $k }} = {{ $v }}
+ {{- end }}
+ {{- if eq $tps "[]interface {}"}}
+ {{ $k }} = [
+ {{- $numOut := len $value }}
+ {{- $numOut := sub $numOut 1 }}
+ {{- range $b, $val := $v }}
+ {{- $i := int64 $b }}
+ {{- if eq $i $numOut }}
+ {{ $val | quote }}
+ {{- else }}
+ {{ $val | quote }},
+ {{- end }}
+ {{- end }}
+ ]
+ {{- end }}
+ {{- if eq $tps "map[string]interface {}"}}
+ [[inputs.{{ $input }}.{{ $key }}.{{ $k }}]]
+ {{- range $foo, $bar := $v }}
+ {{ $foo }} = {{ $bar | quote }}
+ {{- end }}
+ {{- end }}
+ {{- end }}
+ {{- end }}
+ {{- end }}
+ {{- end }}
+ {{- end }}
+ {{ end }}
+{{- end }}
+{{- end -}}
+
+{{- define "default_inputs" -}}
+{{- $input := index . 0 -}}
+{{- $config := index . 1 -}}
+ [[inputs.{{- $input }}]]
+ {{- $tp := typeOf $config -}}
+ {{- if eq $tp "map[string]interface {}" -}}
+ {{- range $key, $value := $config -}}
+ {{- $tp := typeOf $value -}}
+ {{- if eq $tp "string" }}
+ {{ $key }} = {{ $value | quote }}
+ {{- end }}
+ {{- if eq $tp "float64" }}
+ {{ $key }} = {{ $value | int64 }}
+ {{- end }}
+ {{- if eq $tp "int" }}
+ {{ $key }} = {{ $value | int64 }}
+ {{- end }}
+ {{- if eq $tp "bool" }}
+ {{ $key }} = {{ $value }}
+ {{- end }}
+ {{- if eq $tp "[]interface {}" }}
+ {{ $key }} = [
+ {{- $numOut := len $value }}
+ {{- $numOut := sub $numOut 1 }}
+ {{- range $b, $val := $value }}
+ {{- $i := int64 $b }}
+ {{- $tp := typeOf $val }}
+ {{- if eq $i $numOut }}
+ {{- if eq $tp "string" }}
+ {{ $val | quote }}
+ {{- end }}
+ {{- if eq $tp "float64" }}
+ {{ $val | int64 }}
+ {{- end }}
+ {{- else }}
+ {{- if eq $tp "string" }}
+ {{ $val | quote }},
+ {{- end}}
+ {{- if eq $tp "float64" }}
+ {{ $val | int64 }},
+ {{- end }}
+ {{- end }}
+ {{- end }}
+ ]
+ {{- end }}
+ {{- end }}
+ {{- range $key, $value := $config -}}
+ {{- $tp := typeOf $value -}}
+ {{- if eq $tp "map[string]interface {}" }}
+ [[inputs.{{ $input }}.{{ $key }}]]
+ {{- range $k, $v := $value }}
+ {{- $tps := typeOf $v }}
+ {{- if eq $tps "string" }}
+ {{ $k }} = {{ $v | quote }}
+ {{- end }}
+ {{- if eq $tps "float64" }}
+ {{ $k }} = {{ $v | int64 }}.0
+ {{- end }}
+ {{- if eq $tps "int64" }}
+ {{ $k }} = {{ $v | int64 }}
+ {{- end }}
+ {{- if eq $tps "bool" }}
+ {{ $k }} = {{ $v }}
+ {{- end }}
+ {{- if eq $tps "[]interface {}"}}
+ {{ $k }} = [
+ {{- $numOut := len $value }}
+ {{- $numOut := sub $numOut 1 }}
+ {{- range $b, $val := $v }}
+ {{- $i := int64 $b }}
+ {{- if eq $i $numOut }}
+ {{ $val | quote }}
+ {{- else }}
+ {{ $val | quote }},
+ {{- end }}
+ {{- end }}
+ ]
+ {{- end }}
+ {{- if eq $tps "map[string]interface {}"}}
+ [[inputs.{{ $input }}.{{ $key }}.{{ $k }}]]
+ {{- range $foo, $bar := $v }}
+ {{ $foo }} = {{ $bar | quote }}
+ {{- end }}
+ {{- end }}
+ {{- end }}
+ {{- end }}
+ {{- end }}
+ {{- end }}
+{{- end -}}
diff --git a/charts/telegraf-ds/templates/configmap.yaml b/charts/telegraf-ds/templates/configmap.yaml
index a98e15b..9cad427 100644
--- a/charts/telegraf-ds/templates/configmap.yaml
+++ b/charts/telegraf-ds/templates/configmap.yaml
@@ -16,31 +16,18 @@ data:
{{ template "aggregators" .Values.config.aggregators }}
{{ template "outputs" .Values.config.outputs }}
{{ template "monitor_self" .Values.config.monitor_self }}
-
- [[inputs.diskio]]
- [[inputs.kernel]]
- [[inputs.mem]]
- [[inputs.net]]
- [[inputs.processes]]
- [[inputs.swap]]
- [[inputs.system]]
-
- [[inputs.cpu]]
- percpu = true
- totalcpu = true
- collect_cpu_time = false
- report_active = false
-
- [[inputs.disk]]
- ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]
+ {{ template "default_inputs" (list "cpu" .Values.config.cpu) }}
+ {{ template "default_inputs" (list "intel_powerstat" .Values.config.intel_powerstat) }}
+ {{ template "default_inputs" (list "ipmi_sensor" .Values.config.ipmi_sensor) }}
+ {{ template "default_inputs" (list "linux_cpu" .Values.config.linux_cpu) }}
+ {{ template "default_inputs" (list "mem" .Values.config.mem) }}
+ {{- if .Values.pmu_enabled }}
+ {{ template "default_inputs" (list "intel_pmu" .Values.config.intel_pmu) }}
+ {{- end }}
+ {{ template "inputs" .Values.config.inputs }}
{{- if .Values.config.docker_endpoint }}
[[inputs.docker]]
endpoint = {{ .Values.config.docker_endpoint | quote }}
{{- end }}
-
- [[inputs.kubernetes]]
- url = "https://$HOSTIP:10250"
- bearer_token = "/var/run/secrets/kubernetes.io/serviceaccount/token"
- insecure_skip_verify = true
{{- end }}
diff --git a/charts/telegraf-ds/templates/daemonset.yaml b/charts/telegraf-ds/templates/daemonset.yaml
index 1b7f289..f3b0049 100644
--- a/charts/telegraf-ds/templates/daemonset.yaml
+++ b/charts/telegraf-ds/templates/daemonset.yaml
@@ -31,7 +31,7 @@ spec:
{{- end }}
containers:
- name: {{ .Chart.Name }}
- image: "{{ .Values.image.repo }}:{{ .Values.image.tag }}"
+ image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ default "" .Values.image.pullPolicy | quote }}
resources:
{{ toYaml .Values.resources | indent 10 }}
@@ -50,6 +50,8 @@ spec:
- secretRef:
name: {{ .Values.envFromSecret }}
{{- end }}
+ securityContext:
+ {{- toYaml .Values.securityContext | nindent 12 }}
volumeMounts:
- name: varrunutmpro
mountPath: /var/run/utmp
@@ -62,10 +64,19 @@ spec:
mountPath: {{ trimPrefix "unix://" .Values.config.docker_endpoint }}
{{- end }}
- name: config
- mountPath: /etc/telegraf
+ mountPath: /etc/telegraf/telegraf.conf
+ subPath: telegraf.conf
+ readOnly: true
+ - name: lib-modules
+ mountPath: /lib/modules
+ - name: sys-kernel-debug
+ mountPath: /sys/kernel/debug
{{- if .Values.mountPoints }}
{{ toYaml .Values.mountPoints | indent 8 }}
{{- end }}
+ {{- if .Values.pmu_enabled }}
+{{ toYaml .Values.pmu_mountPoints | indent 8 }}
+ {{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
@@ -79,6 +90,14 @@ spec:
{{ toYaml . | indent 8 }}
{{- end }}
volumes:
+ - hostPath:
+ path: /lib/modules
+ type: Directory
+ name: lib-modules
+ - hostPath:
+ path: /sys/kernel/debug
+ type: Directory
+ name: sys-kernel-debug
- name: hostfsro
hostPath:
path: /
@@ -96,6 +115,9 @@ spec:
name: {{ include "telegraf.fullname" . }}
{{- if .Values.volumes }}
{{ toYaml .Values.volumes | indent 6 }}
+ {{- end }}
+ {{- if .Values.pmu_enabled }}
+{{ toYaml .Values.pmu_volumes | indent 6 }}
{{- end }}
hostNetwork: {{ default false .Values.hostNetwork }}
{{- if .Values.dnsPolicy }}
diff --git a/charts/telegraf-ds/templates/events_definition.yaml b/charts/telegraf-ds/templates/events_definition.yaml
new file mode 100644
index 0000000..d54b044
--- /dev/null
+++ b/charts/telegraf-ds/templates/events_definition.yaml
@@ -0,0 +1,36 @@
+{{- if .Values.pmu_enabled }}
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: telegraf-events
+ labels:
+ {{- include "telegraf.labels" . | nindent 4 }}
+data:
+ events_definition.json: |
+ [
+ {
+ "EventCode": "0x00",
+ "UMask": "0x01",
+ "EventName": "INST_RETIRED.ANY",
+ "BriefDescription": "Number of instructions retired. Fixed Counter - architectural event",
+ "PublicDescription": "Counts the number of X86 instructions retired - an Architectural PerfMon event. Counting continues during hardware interrupts, traps, and inside interrupt handlers. Notes: INST_RETIRED.ANY is counted by a designated fixed counter freeing up programmable counters to count other events. INST_RETIRED.ANY_P is counted by a programmable counter.",
+ "Counter": "Fixed counter 0",
+ "PEBScounters": "32",
+ "SampleAfterValue": "2000003",
+ "MSRIndex": "0x00",
+ "MSRValue": "0x00",
+ "CollectPEBSRecord": "2",
+ "TakenAlone": "0",
+ "CounterMask": "0",
+ "Invert": "0",
+ "EdgeDetect": "0",
+ "PEBS": "1",
+ "Data_LA": "0",
+ "L1_Hit_Indication": "0",
+ "Errata": "null",
+ "Offcore": "0",
+ "Deprecated": "0",
+ "Speculative": "0"
+ }
+ ]
+{{- end }}
diff --git a/charts/telegraf-ds/templates/service.yaml b/charts/telegraf-ds/templates/service.yaml
new file mode 100644
index 0000000..cc437b0
--- /dev/null
+++ b/charts/telegraf-ds/templates/service.yaml
@@ -0,0 +1,14 @@
+apiVersion: v1
+kind: Service
+metadata:
+ name: {{ include "telegraf.fullname" . }}
+ labels:
+ {{- include "telegraf.labels" . | nindent 4 }}
+spec:
+ selector:
+ app.kubernetes.io/name: {{ include "telegraf.name" . }}
+ app.kubernetes.io/instance: {{ .Release.Name }}
+ ports:
+ - name: http
+ port: {{ .Values.service.port }}
+ type: {{ .Values.service.type }}
diff --git a/charts/telegraf-ds/templates/serviceaccount.yaml b/charts/telegraf-ds/templates/serviceaccount.yaml
index 8ed4588..7acb677 100644
--- a/charts/telegraf-ds/templates/serviceaccount.yaml
+++ b/charts/telegraf-ds/templates/serviceaccount.yaml
@@ -1,6 +1,8 @@
{{- if .Values.serviceAccount.create }}
apiVersion: v1
kind: ServiceAccount
+imagePullSecrets:
+ - name: "{{ .Values.imagePullSecrets }}"
metadata:
name: {{ include "telegraf.serviceAccountName" . }}
labels:
diff --git a/charts/telegraf-ds/values.yaml b/charts/telegraf-ds/values.yaml
index b4b4e9f..533ba7f 100644
--- a/charts/telegraf-ds/values.yaml
+++ b/charts/telegraf-ds/values.yaml
@@ -3,18 +3,40 @@
## ref: https://hub.docker.com/r/library/telegraf/tags/
image:
- repo: "telegraf"
- tag: "1.27-alpine"
+ repository: "docker.io/starlingx/telegraf"
+ tag: "stx.9.0-v1.27.3"
pullPolicy: IfNotPresent
## Configure resource requests and limits
## ref: http://kubernetes.io/docs/user-guide/compute-resources/
resources:
requests:
memory: 256Mi
- cpu: 0.1
+ cpu: 0
limits:
memory: 2Gi
cpu: 1
+
+imagePullSecrets: default-registry-key
+
+nodeSelector:
+ power-metrics: "enabled"
+
+service:
+ type: ClusterIP
+ port: 9273
+
+# Enable Intel PMU plugin
+pmu_enabled: false
+
+pmu_volumes:
+- name: telegraf-events
+ configMap:
+ name: telegraf-events
+pmu_mountPoints:
+- name: telegraf-events
+ mountPath: /etc/telegraf/events_definition.json
+ subPath: events_definition.json
+
## Pod annotations
podAnnotations: {}
## Pod labels
@@ -50,15 +72,15 @@ env:
value: "/hostfs/sys"
- name: "HOST_MOUNT_PREFIX"
value: "/hostfs"
+ - name: "HOST_ETC"
+ value: "/hostfs/etc"
+ - name: "HOST_RUN"
+ value: "/hostfs/run"
+ - name: "HOST_VAR"
+ value: "/hostfs/var"
## Add custom volumes and mounts
-# volumes:
-# - name: telegraf-output-influxdb2
-# configMap:
-# name: "telegraf-output-influxdb2"
-# mountPoints:
-# - name: telegraf-output-influxdb2
-# mountPath: /etc/telegraf/conf.d
-# subPath: influxdb2.conf
+volumes: {}
+mountPoints: {}
## Tolerations for pod assignment
## ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
@@ -69,7 +91,7 @@ tolerations: []
## If using hostNetwork=true, set dnsPolicy to ClusterFirstWithHostNet
## ref: https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#
-## dnsPolicy: ClusterFirstWithHostNet
+dnsPolicy: ClusterFirstWithHostNet
## If using dnsPolicy=None, set dnsConfig
## ref: https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-dns-config
@@ -85,13 +107,13 @@ tolerations: []
## - name: edns0
rbac:
# Specifies whether RBAC resources should be created
- create: true
+ create: false
serviceAccount:
# Specifies whether a ServiceAccount should be created
create: true
# The name of the ServiceAccount to use.
# If not set and create is true, a name is generated using the fullname template
- # name:
+ name: telegraf
# Annotations for the ServiceAccount
annotations: {}
## Specify priorityClassName
@@ -100,6 +122,11 @@ serviceAccount:
# Specify the pod's SecurityContext, including the OS user and group to run the pod
podSecurityContext: {}
+
+# Specify container SecurityContext, including privileges and capabilities
+securityContext:
+ privileged: true
+
override_config:
toml: ~
# Provide a literal TOML config
@@ -115,10 +142,37 @@ override_config:
# organization = "OurCompany"
# token = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
## Exposed telegraf configuration
-## ref: https://docs.influxdata.com/telegraf/v1.13/administration/configuration/
+## ref: https://docs.influxdata.com/telegraf/v1.27/configuration/
config:
- # global_tags:
- # cluster: "mycluster"
+ global_tags: {}
+
+ # Default plugins to collect power-metrics data
+ cpu:
+ percpu: true
+ totalcpu: true
+ collect_cpu_time: false
+ report_active: false
+ intel_powerstat:
+ cpu_metrics: ["cpu_frequency","cpu_busy_frequency","cpu_temperature","cpu_c0_state_residency","cpu_c1_state_residency","cpu_c6_state_residency","cpu_busy_cycles"]
+ package_metrics: ["current_power_consumption","current_dram_power_consumption","thermal_design_power","cpu_base_frequency","uncore_frequency"]
+ read_method: "concurrent"
+ intel_pmu:
+ event_definitions: ["/etc/telegraf/events_definition.json"]
+ core_events:
+ events: ["INST_RETIRED.ANY"]
+ ipmi_sensor:
+ interval: "30s"
+ timeout: "20s"
+ metric_version: 1
+ use_sudo: false
+ linux_cpu:
+ metrics: ["cpufreq"]
+ mem:
+
+ aggregators: {}
+
+ processors: {}
+
agent:
interval: "10s"
round_interval: true
@@ -134,15 +188,12 @@ config:
hostname: "$HOSTNAME"
omit_hostname: false
outputs:
- - influxdb:
- urls:
- - "http://influxdb.monitoring.svc:8086"
- database: "telegraf"
- retention_policy: ""
- timeout: "5s"
- username: ""
- password: ""
- user_agent: "telegraf"
- insecure_skip_verify: false
+ - prometheus_client:
+ listen: ":9273"
+
+ # Specify additional plugins to be added to telegraf
+ # following the same pattern as outputs
+ inputs: {}
+
monitor_self: false
- docker_endpoint: "unix:///var/run/docker.sock"
+ docker_endpoint: ""
--
2.25.1

View File

@ -0,0 +1 @@
0001-Patch-telegraf-helm-chart.patch

View File

@ -0,0 +1,20 @@
#!/usr/bin/make -f
export DH_VERBOSE = 1
export ROOT = debian/tmp
export APP_FOLDER = $(ROOT)/usr/lib/helm
%:
dh $@
override_dh_auto_build:
cp Makefile charts
cd charts && make telegraf-ds
override_dh_auto_install:
# Install the app tar file.
install -d -m 755 $(APP_FOLDER)
install -p -D -m 755 charts/telegraf-*.tgz $(APP_FOLDER)
override_dh_auto_test:

View File

@ -0,0 +1 @@
3.0 (quilt)

View File

@ -0,0 +1 @@
usr/lib/helm/*

View File

@ -0,0 +1,14 @@
---
debname: telegraf-helm
debver: 1.1-12
dl_path:
name: telegraf-ds-1.1.12.tar.gz
url: https://github.com/influxdata/helm-charts/archive/telegraf-ds-1.1.12.tar.gz
sha256sum: 7b2dd30eb6de734eff82b8fde1be57c4bad4823c4a59218961d15a4da424af16
src_files:
- telegraf-helm/files/Makefile
revision:
dist: $STX_DIST
GITREVCOUNT:
BASE_SRCREV: 5304930dae1e62dbea8cdc59d756b2b1fcae76a5
SRC_DIR: ${MY_REPO}/stx/app-power-metrics/telegraf-helm

View File

@ -0,0 +1,42 @@
#
# Copyright 2017 The Openstack-Helm Authors.
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# It's necessary to set this because some environments don't link sh -> bash.
SHELL := /bin/bash
TASK := build
EXCLUDES := doc tests tools logs tmp
CHARTS := $(filter-out $(EXCLUDES), $(patsubst %/.,%,$(wildcard */.)))
.PHONY: $(EXCLUDES) $(CHARTS)
all: $(CHARTS)
$(CHARTS):
@if [ -d $@ ]; then \
echo; \
echo "===== Processing [$@] chart ====="; \
make $(TASK)-$@; \
fi
init-%:
if [ -f $*/Makefile ]; then make -C $*; fi
lint-%: init-%
if [ -d $* ]; then helm lint $*; fi
build-%: lint-%
if [ -d $* ]; then helm package $*; fi
clean:
@echo "Clean all build artifacts"
rm -f */templates/_partials.tpl */templates/_globals.tpl
rm -f *tgz */charts/*tgz */requirements.lock
rm -rf */charts */tmpcharts
%:
@:

View File

@ -1,3 +1,3 @@
# hacking pulls in flake8
hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0
bashate >= 0.2
hacking>=1.1.0,<=2.0.0 # Apache-2.0
bashate >= 0.2

View File

@ -1,11 +1,13 @@
[tox]
envlist = linters
minversion = 2.3
minversion = 2.9
skipsdist = True
sitepackages=False
[testenv]
install_command = pip install -U {opts} {packages}
install_command = pip install -U \
{opts} {packages} \
-c{env:TOX_CONSTRAINTS_FILE:https://opendev.org/starlingx/root/raw/branch/master/build-tools/requirements/debian/upper-constraints.txt}
setenv =
VIRTUAL_ENV={envdir}
OS_STDOUT_CAPTURE=1
@ -21,7 +23,6 @@ allowlist_externals =
passenv =
XDG_CACHE_HOME
[testenv:bashate]
# Treat all E* codes as Errors rather than warnings using: -e 'E*'
commands =