Support Questions

Find answers, ask questions, and share your expertise

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2028' in position 108: ordinal not in range(128)

avatar
Rising Star

I got this error in Starting AMBARI-METRICES from Ambari WEB-UI after upgrading.

Traceback (most recent call last):

File "/var/lib/ambari-agent/cache/common-services/AMBARI_METRICS/0.1.0/package/scripts/metrics_collector.py", line 131, in <module>

AmsCollector().execute()

File "/usr/lib/python2.6/site-packages/resource_management/libraries/script/script.py", line 219, in execute

method(env)

File "/var/lib/ambari-agent/cache/common-services/AMBARI_METRICS/0.1.0/package/scripts/metrics_collector.py", line 44, in start

self.configure(env, action = 'start') # for security

File "/var/lib/ambari-agent/cache/common-services/AMBARI_METRICS/0.1.0/package/scripts/metrics_collector.py", line 41, in configure

ams(name='collector')

File "/usr/lib/python2.6/site-packages/ambari_commons/os_family_impl.py", line 89, in thunk

return fn(*args, **kwargs)

File "/var/lib/ambari-agent/cache/common-services/AMBARI_METRICS/0.1.0/package/scripts/ams.py", line 202, in ams

group=params.user_group

File "/usr/lib/python2.6/site-packages/resource_management/core/base.py", line 154, in __init__

self.env.run()

File "/usr/lib/python2.6/site-packages/resource_management/core/environment.py", line 152, in run

self.run_action(resource, action)

File "/usr/lib/python2.6/site-packages/resource_management/core/environment.py", line 118, in run_action

provider_action()

File "/usr/lib/python2.6/site-packages/resource_management/libraries/providers/xml_config.py", line 67, in action_create

encoding = self.resource.encoding

File "/usr/lib/python2.6/site-packages/resource_management/core/base.py", line 154, in __init__

self.env.run()

File "/usr/lib/python2.6/site-packages/resource_management/core/environment.py", line 152, in run

self.run_action(resource, action)

File "/usr/lib/python2.6/site-packages/resource_management/core/environment.py", line 118, in run_action

provider_action()

File "/usr/lib/python2.6/site-packages/resource_management/core/providers/system.py", line 90, in action_create

content = self._get_content()

File "/usr/lib/python2.6/site-packages/resource_management/core/providers/system.py", line 127, in _get_content

return content()

File "/usr/lib/python2.6/site-packages/resource_management/core/source.py", line 51, in __call__

return self.get_content()

File "/usr/lib/python2.6/site-packages/resource_management/core/source.py", line 142, in get_content

rendered = self.template.render(self.context)

File "/usr/lib/python2.6/site-packages/ambari_jinja2/environment.py", line 891, in render

return self.environment.handle_exception(exc_info, True)

File "<template>", line 5, in top-level template code

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2028' in position 108: ordinal not in range(128)

1 ACCEPTED SOLUTION

avatar
Rising Star

@Balkrishna,

The problem is with special characters in the KAFKA service metrics file. We use this file as a part of stack_advisor calculations for AMS split points. Following is a grep on non ASCII characters that reveals the problem :-

grep --color='auto' -P -n "[\x80-\xFF]" /var/lib/ambari-server/resources/common-services/AMBARI_METRICS/0.1.0/package/files/service-metrics/KAFKA.txt

This will show you the ascii characters present in the file as,

Output:-43:��kafka.network.RequestMetrics.RequestsPerSec.request.OffsetFetch.count�� 45:��kafka.network.RequestMetrics.RequestsPerSec.request.OffsetCommit.count 47:kafka.network.RequestMetrics.RequestsPerSec.request.LeaderAndIsr.1MinuteRate��

Use /var/lib/ambari-server/resources/scripts/configs.sh to modify and get values from ambari-server as,

/var/lib/ambari-server/resources/scripts/configs.sh -u admin -p ADMIN_PASSWORD -port 8080 get localhost CLUSTER_NAME ams-site

Check the value of "timeline.metrics.cluster.aggregate.splitpoints" and "timeline.metrics.host.aggregate.splitpoints", Look for special non-ascii characters example:

"dfs.datanode.ReplaceBlockOpAvgTime,kafka.network.RequestMetrics.RequestsPerSec.request.JoinGroup.1MinuteRate ,master.Master.ProcessCallTime_num_ops,regionserver.Server.blockCacheEvictionCount"

Here after 1MinuteRate there is space which will shown as a special character on browser through API call as,

"http://AMBARI_SERVER_HOSTS:8080/api/v1/clusters/CLUSTER_NAME/configurations?type=ams-site"

Take latest tag from it at the bottom of page. and put it on browser you will see the special character as,

"timeline.metrics.cluster.aggregate.splitpoints":"dfs.datanode.ReplaceBlockOpAvgTime,kafka.network.RequestMetrics.RequestsPerSec.request.JoinGroup.1MinuteRate
,master.Master.ProcessCallTime_num_ops,regionserver.Server.blockCacheEvictionCount"

To resolve this issue use,

/var/lib/ambari-server/resources/scripts/configs.sh -u admin -p ADMIN_PASSWORD -port 8080 set localhost CLUSTER_NAME ams-site timeline.metrics.cluster.aggregate.splitpoints dfs.datanode.ReplaceBlockOpAvgTime,kafka.network.RequestMetrics.RequestsPerSec.request.JoinGroup.1MinuteRate,master.Master.ProcessCallTime_num_ops,regionserver.Server.blockCacheEvictionCount

To change second property paramater use:-

/var/lib/ambari-server/resources/scripts/configs.sh -u admin -p ADMIN_PASSWORD -port 8080 get localhost CLUSTER_NAME ams-site

/var/lib/ambari-server/resources/scripts/configs.sh -u admin -p ADMIN_PASSWORD -port 8080 set localhost CLUSTER_NAME ams-site timeline.metrics.host.aggregate.splitpoints EventTakeSuccessCount,cpu_idle,dfs.FSNamesystem.ExcessBlocks,dfs.datanode.ReadBlockOpNumOps,disk_total,jvm.JvmMetrics.LogError,kafka.controller.ControllerStats.LeaderElectionRateAndTimeMs.99percentile,kafka.network.RequestMetrics.RequestsPerSec.request.FetchFollower.5MinuteRate,kafka.network.RequestMetrics.RequestsPerSec.request.UpdateMetadata.1MinuteRate,kafka.server.BrokerTopicMetrics.FailedFetchRequestsPerSec.meanRate,master.AssignmentManger.ritCount,master.FileSystem.MetaHlogSplitTime_95th_percentile,mem_shared,proc_total,regionserver.Server.Append_median,regionserver.Server.Replay_95th_percentile,regionserver.Server.totalRequestCount,rpcdetailed.rpcdetailed.GetBlockLocationsAvgTime,write_bps ### Restart the Service

View solution in original post

1 REPLY 1

avatar
Rising Star

@Balkrishna,

The problem is with special characters in the KAFKA service metrics file. We use this file as a part of stack_advisor calculations for AMS split points. Following is a grep on non ASCII characters that reveals the problem :-

grep --color='auto' -P -n "[\x80-\xFF]" /var/lib/ambari-server/resources/common-services/AMBARI_METRICS/0.1.0/package/files/service-metrics/KAFKA.txt

This will show you the ascii characters present in the file as,

Output:-43:��kafka.network.RequestMetrics.RequestsPerSec.request.OffsetFetch.count�� 45:��kafka.network.RequestMetrics.RequestsPerSec.request.OffsetCommit.count 47:kafka.network.RequestMetrics.RequestsPerSec.request.LeaderAndIsr.1MinuteRate��

Use /var/lib/ambari-server/resources/scripts/configs.sh to modify and get values from ambari-server as,

/var/lib/ambari-server/resources/scripts/configs.sh -u admin -p ADMIN_PASSWORD -port 8080 get localhost CLUSTER_NAME ams-site

Check the value of "timeline.metrics.cluster.aggregate.splitpoints" and "timeline.metrics.host.aggregate.splitpoints", Look for special non-ascii characters example:

"dfs.datanode.ReplaceBlockOpAvgTime,kafka.network.RequestMetrics.RequestsPerSec.request.JoinGroup.1MinuteRate ,master.Master.ProcessCallTime_num_ops,regionserver.Server.blockCacheEvictionCount"

Here after 1MinuteRate there is space which will shown as a special character on browser through API call as,

"http://AMBARI_SERVER_HOSTS:8080/api/v1/clusters/CLUSTER_NAME/configurations?type=ams-site"

Take latest tag from it at the bottom of page. and put it on browser you will see the special character as,

"timeline.metrics.cluster.aggregate.splitpoints":"dfs.datanode.ReplaceBlockOpAvgTime,kafka.network.RequestMetrics.RequestsPerSec.request.JoinGroup.1MinuteRate
,master.Master.ProcessCallTime_num_ops,regionserver.Server.blockCacheEvictionCount"

To resolve this issue use,

/var/lib/ambari-server/resources/scripts/configs.sh -u admin -p ADMIN_PASSWORD -port 8080 set localhost CLUSTER_NAME ams-site timeline.metrics.cluster.aggregate.splitpoints dfs.datanode.ReplaceBlockOpAvgTime,kafka.network.RequestMetrics.RequestsPerSec.request.JoinGroup.1MinuteRate,master.Master.ProcessCallTime_num_ops,regionserver.Server.blockCacheEvictionCount

To change second property paramater use:-

/var/lib/ambari-server/resources/scripts/configs.sh -u admin -p ADMIN_PASSWORD -port 8080 get localhost CLUSTER_NAME ams-site

/var/lib/ambari-server/resources/scripts/configs.sh -u admin -p ADMIN_PASSWORD -port 8080 set localhost CLUSTER_NAME ams-site timeline.metrics.host.aggregate.splitpoints EventTakeSuccessCount,cpu_idle,dfs.FSNamesystem.ExcessBlocks,dfs.datanode.ReadBlockOpNumOps,disk_total,jvm.JvmMetrics.LogError,kafka.controller.ControllerStats.LeaderElectionRateAndTimeMs.99percentile,kafka.network.RequestMetrics.RequestsPerSec.request.FetchFollower.5MinuteRate,kafka.network.RequestMetrics.RequestsPerSec.request.UpdateMetadata.1MinuteRate,kafka.server.BrokerTopicMetrics.FailedFetchRequestsPerSec.meanRate,master.AssignmentManger.ritCount,master.FileSystem.MetaHlogSplitTime_95th_percentile,mem_shared,proc_total,regionserver.Server.Append_median,regionserver.Server.Replay_95th_percentile,regionserver.Server.totalRequestCount,rpcdetailed.rpcdetailed.GetBlockLocationsAvgTime,write_bps ### Restart the Service